Recently VS hinted me to use the:
var str = "foo";
var str2 = str[^2..];
Instead of the:
var str = "foo";
var str2 = str.Substring(str.Length - 2);
So, my question is are there any differences between the str[^2..]
and the str.Substring(str.Length - 2)
? I think it is a new C# feature, but I was not able to find any documentation about it. So, I do not know how it is called and what version of C# does it come with.
Here is what I was trying to google:
^ in string access c#
I did not get any related results. Should I google something else?