Listnumbers = new List { 1, 2, 3, 4, 5 }; int count = numbers.Count(); Console.WriteLine(count); //Output: 5
string text = "Hello World"; int count = text.Count(c => c == 'o'); Console.WriteLine(count); //Output: 2
enum Colors { Red, Green, Blue } string description = Colors.Red.GetType().GetMember(Colors.Red.ToString())[0].GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault(); Console.WriteLine(description); //Output: null //Add description attribute to enum public enum Colors { [Description("This is a red color")] Red, [Description("This is a green color")] Green, [Description("This is a blue color")] Blue } string description = Colors.Red.GetType().GetMember(Colors.Red.ToString())[0].GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault(); Console.WriteLine(description); //Output: This is a red colorLibrary: System.ComponentModel (for DescriptionAttribute)