Problem
I want to get the last digits of this string
, so I used the Substring()
method, however I had to use the variable "numero" again within the Substring()
method.
string numero = "123456789";
string final = numero.Substring(numero.Length - 4);
Console.Write(final);
Is there any way to reference the numero
variable generically in its own method? Something like:
string final = numero.Substring(reference.Length - 4);
I used the word "reference" only as an example, I am aware that so that it will not work.
Because I want this
As this is very simple to use the variable number, however in the code in which I need to perform this procedure the variable I am using is in a chain of methods and submodes, so the reference leaves the code confusing. As a palliative I did the following:
string numero = referenciaMuitoGrandeBlaBla;
string final = numero.Substring(numero.Length - 4);
Console.Write(final);
It does help, but I do not want to use it this way, as there may be a way to reference it.