In reference to using .Equals() or == on strings, here is a question in regards to checking for string.Empty and null objects.
In comparing string.Empty and null objects, should I use == or should I use .Equals()?
// Add vars to instance variables
for (int i = 0; i < paramFirstList.Count; i++)
{
// if the key is null, replace it
// with a "null" string
if (paramFirstList[i] == null)
{
_firstList.Add("null");
}
else if (paramFirstList[i] == string.Empty)
{
_firstList.Add("empty");
}
else
{
// Do something
}
}
P.S. I understand it's better to store null and string.Empty as their object types, but for this particular purpose, it is in my requirements to store them as a string representation :).
P.P.S. Added hungarian notation for the sake of question clarity
String.Emptyandnullbut then you are adding"empty"and"null". Also youP.Sis even more confusing.nullhe is storing"null"and while he knows he should store them as object types (ienull) he is storing them as a string representation (ie"null"). His checks are workign on string.empty and null though so I'm not sure why you are worrying about what he is putting in the list.s.Equals(null)whensis in factnullyou'll end up with anNullReferenceException.