I have a class which contains a nullable strings, I want to make a check to see whether they stay null or somebody has set them.
simliar to strings, the class contains integers which are nullable, where i can perform this check by doing an equality comparison with the .HasValue() method - it seems like strings dont have this?
So how do check whether it goes from null to notNull?
public class Test
{
public string? a
public string? b
public int? c
}
var oldQ = new Test(c=123)
var newQ = new Test(c=546)
bool isStilValid = newQ.c.HasValue() == oldQ.c.HasValue() //(this is not possible?)&& newQ.b.HasValue() == oldQ.b.HasValue()
why is this not possible?
s == null
ands != null
? – KantarHasValue
. Only nullable value types have such a thing. – Unitive.HasValue
. Test for (in)equality withnull
. – MassageHasValue
– Enrapturestring?
in c# version lower than8
. Are you usingc# 8
? – InkleHasValue
andValue
are properties, not methods so invoking.HasValue()
would be wrong anyway – Complicate