The following code is what I\'ve been using to retrieve user information from a sql database.
string userName = LoginUser.UserName;
strin
As of C# 6.0 you can use the Null conditional operator ?.
(or ?[]
for arrays).
The null conditional operator simplifies the statement to:
if (dt?.Rows?.Count > 0)
This returns false when:
dt
is nulldt.Rows
is nulldt.Rows.Count
is 0Using the null conditional operator you can avoid manually checking both the data table and count properties, eg if (dt != null && dt.Rows.Count > 0)