List Names = new List(); Names.Add("Saurabh"); Names.Add("Somu"); Names.Add("Sandy"); //For every item in the list, say you want to append the last name "Somu" and print it //WITHOUT ForEach() foreach (string name in Names) { Console.WriteLine(name + " Somu"); } //WITH ForEach Names.ForEach(delegate(string name) { Console.WriteLine(...
Yield Keyword
class Program { static void Main(string[] args) { List Names = new List(); Names.Add("saurabh"); Names.Add("somu"); Names.Add("vivek"); foreach (string item in GetNames(Names)) { Console.WriteLine(item); } } public static IEnumerable GetNames(List...
?? keyword
?? keyword is used to check null.Example using if-else statement:-if (tempString == null){ x = "Null string";} else{ x = tempString ;} Console.WriteLine(x); Example using ?? Keywordstring tempString = null; string x = tempString ?? "Null string"; Console.WriteLine(x); //Prints "Null stri...