Finding all the Elements of a Range from Start to End in C#
Last Updated :
28 Jun, 2021
The Range Structure is introduced in C# 8.0. It represents a range that has a start and end indexes. You are allowed to find all the range object starting from the start index to end with the help of All Property provided by the Range struct. This property always returns 0..^0 range.
Syntax:
public static property Range All { Range get(); };
Here, Range represents the index from start to end.
Example 1:
CSharp
using System;
namespace range_example {
class GFG {
static void Main( string [] args)
{
var r = new Range(0, 5);
var new_r = Range.All;
Console.WriteLine(new_r);
}
}
}
|
Output:
0..^0
Example 2:
CSharp
using System;
namespace range_example {
class GFG {
static void Main( string [] args)
{
int [] arr = new int [10] {23, 45, 67, 78,
89, 34, 89, 43, 67, 89};
var value = Range.All;
var a = arr[value];
Console.WriteLine( "Range: " + value);
Console.WriteLine( "Numbers: " );
foreach ( var i in a)
Console.Write($ "{i}, " );
}
}
}
|
Output:
Range: 0..^0
Numbers:
23, 45, 67, 78, 89, 34, 89, 43, 67, 89,
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...