I have the following function in C#:
public string getRowKey(string topic, string rk)
{
return string.Join("", from s in topic.Split('.')
select s.PadLeft(2, '0')).PadRight(4, '0') +
rk.Substring(4);
}
I have a problem because if rk is null or equal to “” then the function is failing. Can someone explain how I can fix this. I am getting an error about index values. Note that if rk is null or “” then I just don’t want that last part with rk.Substring(4) added.
A simple use of ternary operator
?:and functionstring.IsNullOrEmpty(string)would suffice