Reputation: 183
I have a string
Lat
that has word in it, and I want to store it's last letter in a new string
, but it gives me an error: "cannot implicitly convert "char" to string"
current =Lat[j];
My current
is a string
, when I try to use #.ToString
, it gives me another error: Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method?
Upvotes: 1
Views: 1389
Reputation: 4002
If you want the last character in your string, use System.Linq
to retrieve the last letter.
string newString = original.Last().ToString();
// original.Last() gives you a char
// .ToString function after changes it to a string.
Upvotes: 0
Reputation: 1700
either
current =Lat[j].ToString();
OR declare current as a char anyway (Can't tell from your usage if this is a good idea)
Upvotes: 0
Reputation: 25695
use #.ToString()
method to convert it to a string.
like this: current = Lat[j].ToString()
Upvotes: 0
Reputation: 152521
Simplest way is
current = Lat[j].ToString();
or
current = Lat.Substring(Lat.Length - 1);
but it's a bit odd to access a string by it's indexer - if you post more code there may be a cleaner way to get you want you need.
Upvotes: 1