Full overview over variants: I would like to extend the existing answer mentioning using new ranges in C# 8 or higher:
Just slicing with mystring[^4..]
(here example 3) seems very easy, but this has some pitfalls as you will see:
To make the code usable for all possible strings, even those shorter than 4, there is some form of condition needed! If you want to copy code, I suggest example 5 or 6.
string mystring ="C# 8.0 finally makes slicing possible";
1: Slicing taking the end part- by specifying how many characters to omit from the beginning- this is, what VS 2019 suggests:
string example1 = mystring[Math.Max(0, mystring.Length - 4)..] ;
2: Slicing taking the end part- by specifying how many characters to take from the end:
string example2 = mystring[^Math.Min(mystring.Length, 4)..] ;
3: Slicing taking the end part- by replacing Max/Min with the ?: operator:
string example3 = (mystring.length > 4)? mystring[^4..] : mystring);
Personally, I like the second and third variant more than the first.
MS doc reference for Indices and ranges:
Null? But we are not done yet concerning universality. Every example so far will throw an exception for null strings. To consider null (if you don´t use non-nullable strings with C# 8 or higher), and to do it without 'if' (classic example 'with if' already given in another answer) we need:
4: Slicing considering null- by specifying how many characters to omit:
string example4 = mystring?[Math.Max(0, mystring.Length - 4)..] ?? string.Empty;
5: Slicing considering null- by specifying how many characters to take:
string example5 = mystring?[^Math.Min(mystring.Length, 4)..] ?? string.Empty;
6: Slicing considering null with the ?: operator (and two other '?' operators ;-) :
(You cannot put that in a whole in a string interpolation e.g. for WriteLine.)
string example6 = (mystring?.Length > 4) ? filePath[^4..] : mystring ?? string.Empty;
7: Equivalent variant with good old Substring() for C# 6 or 7.x:
(You cannot put that in a whole in a string interpolation e.g. for WriteLine.)
string example7 = (mystring?.Length > 4) ? mystring.Substring(mystring.Length- 4) : mystring ?? string.Empty;
Graceful degradation?
I like the new features of C#. Putting them on one line like in the last examples maybe looks a bit excessive. We ended up a little perl´ish didn´t we?
But it´s a good example for learning and ok for me to use it once in a tested library method.
Even better that we can get rid of null in modern C# if we want and avoid all this null-specific handling.
Such a library/extension method as a shortcut is really useful. Despite the advances in C# you have to write your own to get something easier to use than repeating the code above for every small string manipulation need.
I am one of those who began with BASIC, and 40 years ago there was already Right$(,). Funny, that it is possible to use Strings.Right(,) from VB with C# still too as was shown in another answer.
This was and is very easy to use without having all the edge cases..
C# has chosen precision over graceful degradation (in opposite to old BASIC) by which I mean, it always throws an exception if something not clear happens instead of using a default which works for most cases..
Consequent, but I don't think that this way has much future as last examples show.
Having default configurations with options would be more convenient. Anyway it is easy to overcome this with some self-written library routines.
So copy any appropriate variant you like in these answers and define a graceful shortcut function for yourself, mine is an extension function called RightChars(int).