Fragrance
|
In the latest version of C# i.e. 8.0 Microsoft added two new operators i.e. Index and Range operators. Also, this features is only available in .Net Core 3. In this blog I will try to explain that in a simpler way. Index operator (^) Previously C# had no way of indexing the collection from the end, so with unary operator hat (^) now developer can index from the end. Below is the example One more thing to consider is that the purpose of unary operator hat (^) in regex expression is different compared to used in indexing. Index operators works for all the operators which has a Count or Length property and single integer indexer. So it will work fine for both Array and List but won't work for Dictionary or HashSet since its a set collection i.e. unordered. Range Operator (..) The purpose of the range operator is to slice the collection. Below is the example In range operator, start index is always inclusive and end index is always exclusive. Also range operator works only for the array and not for List
Conclusion I personally liked both Index operator and the Range operator but bit restricted since I can't use range operator for List.
Comments
|
Categories
All
Archives
May 2020
|