Answers for "c# loop through object"

C#
4

loop over object properties c#

foreach (PropertyInfo prop in someObject.GetType().GetProperties())
{
    Console.WriteLine($"{prop.Name}: {prop.GetValue(someObject, null)}");
}
Posted by: Guest on November-12-2020
1

C# loop through array of objet

List<string> names = new List<string>() { "Suresh Dasari", "Rohini Alavala", "Trishika Dasari" };

            foreach (string name in names)

            {

                Console.WriteLine(name);

            }
Posted by: Guest on June-12-2020
2

c# loop through object

static void Main()
{
    foreach (int number in SomeNumbers())
    {
        Console.Write(number.ToString() + " ");
    }
    // Output: 3 5 8
    Console.ReadKey();
}

public static System.Collections.IEnumerable SomeNumbers()
{
    yield return 3;
    yield return 5;
    yield return 8;
}
Posted by: Guest on March-24-2020

C# Answers by Framework

Browse Popular Code Answers by Language