Why does string.IsNullOrEmpty() not work with null strings?


hi all,

i have property defined as:

[datamember(isrequired = false)] public string? last_name { get; set; }

when try enter following line, error:

if (!string.isnullorempty(request.last_name))

the error says isnullorempty has invalid arguments. if change property non null (i.e. remove ?), isnullorempty happy camper.

so confused... why have function check null values when function not accept null values check?

or missing obvious?

thanks!


me (and yes, mark correct answers)


hi,

here ? means, have made property nullable <string> type. however,

system.string reference type , "nullable". nullable<t> , ? suffix value types such int32.

change property to:-

[datamember(isrequired = false)] public string last_name { get; set; }


isnullorempty check work, once covert property string type.


happy coding!! if post answers question please 'mark answer' , 'vote helpful' if helps you.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'