You must Sign In to post a response.
  • Category: .NET

    How to print using console application ?


    Are you looking for a way to print using console application ? then read this thread to know how to print it



    hi guys ,

    i want to print my name 10 or more time in c# .net console application , so pls tell me how to do ,,, thnks
  • #743556
    Use a For Loop



    for(Int I=0;i<100;i++)
    {
    Console.WriteLine("Anil");
    }

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #743558
    Hi,
    Here you go with full code,

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 10; i++)
    {
    Console.WriteLine("www.DotNetSpider.com");

    }
    Console.Read();
    }

    }
    }


    Regards,
    Asheej T K

  • #743567
    Hi,

    You do this using extension methods as shown below. You can pass the number to the method with this extension

    using System;
    namespace ExtensionSample
    {
    class Program
    {
    static void Main(string[] args)
    {
    10.Times("My Name is xxxx");
    Console.ReadLine();
    }
    }
    static class CountSample
    {
    public static void Times(this Int32 i, String str)
    {
    for (int j = 0; j < i; j++)
    {
    Console.WriteLine(str);
    }
    }
    }
    }

  • #743568
    Simple, use for...loop and accomplish your task


    for(int iCount=0;iCount<100;iCount++)
    {
    Console.WriteLine("My name");
    }


    OR you can do it with while loop too, see below snippet

    int iCount = 0;
    While (iCount<100)
    {
    Console.WriteLine("My name");
    iCount++;
    }


    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #743587
    Hello You can use following

    int iNoOfResult=0;
    Console.WriteLine("Enter How Many times you want to print your sweet name");
    iNoOfResult = Convert.ToInt32(Console.ReadLine());
    for(int iCnt=0;iCnt<iNoOfResult ;iCnt++)
    {
    Console.WriteLine("Your sweet name");
    }

  • #743846
    namespace MyName
    {
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 10; i++)
    {
    Console.WriteLine("My Name is: India");

    }
    Console.Read();
    }

    }
    }
    http://microsoft-techies.blogspot.com/2014/04/print-text-using-console.html

  • #744558
    Hi,

    print using console application--

    using System;

    class Program
    {
    static void Main()
    {

    int valueInt = 4;
    Console.WriteLine(valueInt);

    string valueString = "abc";
    Console.WriteLine(valueString);

    bool valueBool = false;
    Console.WriteLine(valueBool);
    }
    }

    Regards

    Regards,
    Dipti Choudhari


  • Sign In to post your comments