Ongoing/String

for foreach [C#] string

More Code 2018. 6. 20. 19:37


using System;

namespace Console1
{
class Program
{
static void Main(string[] args)
{
string words = "Hello";

foreach (var c in words)
{
Console.WriteLine(c);
}
}
}
}

/* Output
H
e
l
l
o
*/



using System;

namespace Console1
{
class Program
{
static void Main(string[] args)
{
string words = "Hello";

for (int i = 0; i < words.Length; i++)
{
Console.WriteLine(words[i]);
}
}
}
}

/* Output
H
e
l
l
o
*/