I have a variable called full_name if the full_name has a string length > 5 I would like to set nm to the first 4 characters of full_name otherwise I would like to set nm to all the characters of full_name.
var nm;
if (full_name.Length > 5)
{
nm = full_name.Substring(0, 4);
}
else
{
nm = full_name;
};
I'm totally confused with the "?" operator.
Could I use it for this ?
var nm = full_name.Length > 5 ? full_name.Substring(0, 4) : full_name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With