Answers for "for list c#"

C#
10

c# loop through list

using System;
using System.Collections.Generic;
 
namespace forgetCode {
    class program {
        public static void Main() {
 
            List<int> list = new List<int>();
            list.Add(1);
            list.Add(2);
            list.Add(3);
 
            foreach (int item in list) { // Loop through List with foreach
                Console.WriteLine(item);
            }
 
            for (int i = 0; i < list.Count; i++) { // Loop through List with for
                Console.WriteLine(list[i]);
            }
        }
    }
}

/*
Outputs:
1
2
3
1
2
3
*/
Posted by: Guest on February-10-2020
1

c# list foreach

someList.ForEach(x => { if(x.RemoveMe) someList.Remove(x); });
Posted by: Guest on August-11-2020
1

c# list.foreach

List<string> someList = <some way to init>
someList.ForEach(delegate(string s) {
    <process the string>
});
Posted by: Guest on May-28-2020
1

c# list object

List<object> Obj = New List<object>();

Obj.Add((cast any)object);
Posted by: Guest on September-17-2020

C# Answers by Framework

Browse Popular Code Answers by Language