```
public class Solution {
public int LengthOfLastWord(string s) {
if (s.Length == 0)
{
return 0;
}
int result = 0;
for (int i = s.Length-1; i >= 0; i--)
{
if (s[i] != ' ')
{
result++;
}
else if (s[i] == ' ' && result != 0)
{
return result;
}
}
return result;
}
}
```