BlueBarren BlueBarren - 2 months ago 24
C# Question

SamAccountName to UpperCase

Does the

SamAccountName
property of
UserPrincipal
not return a string? I'm trying to take the first character of my
SamAccountName
and convert it
.ToUpperCase()
but
.ToUpperCase()
is not available for
SamAccountName


private void firstCharToUppercase(Prinicpal principal)
{
UserPrinicpal user = principal as UserPrincipal;
user.SamAccountName[0].toUpperCase();
}

Answer

As clearly denoted by the documentation, SamAccountName returns a string.

However, by using an indexer, you are retrieving the first character as type char, not type string.

You need to call ToString() on the result first.

user.SamAccountName[0].ToString().ToUpper();