0
Write a c# program to print your name 10 times on console using goto statement?
3 Antworten
+ 3
There is in fact a goto in C#. (https://msdn.microsoft.com/en-gb/library/13940fs2.aspx)
I recommend avoiding it and only using it in switches and loops when really necessary.
+ 2
there is no command like "goto" in c#. your code gets unreadable if your working on a larger project. for your purpose a for or while loop fits best, like
string name = "John Doe";
for(int i = 0; i < 10; i++)
{
Console.WriteLine("Hello {0}", name);
}
+ 1
using System;
namespace Foobar
{
class Program
{
static int foo = 0;
static void Main()
{
//goto version - NOT recommended
bar:
Console.WriteLine("You Name");
i++;
if (i < 10)
goto bar;
//for (; ;) version - recommended
for (int i = 0; i < 10; i++)
Console.WriteLine("Your Name");
}
}
}