LINQ in C# - Examples - Range, Repeat, Empty - Generation

Range - Example

IEnumerable<int> ints = Enumerable.Range(1, 5);

            foreach (var item in ints)
                Console.WriteLine(item);
 //Output
1
2
3
4
5

Repeat - Example

IEnumerable<int> ints = Enumerable.Repea(7, 5);

            foreach (var item in ints)
                Console.WriteLine(item);
 //Output
7
7
7
7
7

Empty- Example

  • The Empty operator generates an empty sequence of a specified type.
IEnumerable<string> strings= Enumerable.Empty<string>();         
                Console.WriteLine(strings.count());
 //Output
0

No comments:

Post a Comment

Framework Fundamentals - String - Comparing Strings

In comparing two values, the .NET Framework differentiates the concepts of equality comparison and order comparison . Equality compariso...