I came here to resolve a question and I left with another. I did not know that it was possible to define an object of the same class within the definition of the class itself. Either way, thanks for resolving my concerns about Null-conditional operators
@jfversluis3 жыл бұрын
Haha the more you know... Glad you enjoyed it! Any other questions you might have?
@johnb25723 жыл бұрын
Nice, very useful. Thank you.
@jfversluis3 жыл бұрын
Glad it was helpful!
@itamarcus3 жыл бұрын
good tips... and now we also know that Gerald loves gardening ^_^
@jfversluis3 жыл бұрын
Hahaha actually… he does not 😜
@klasseka3 жыл бұрын
I often use combo of operators ?. and ?? . It`s useful if need to react on null like Console.WriteLine(person?.Name ?? "A person has no name");
@jfversluis3 жыл бұрын
That makes total sense! I didn't want to take on too much in one video, but more on this is coming :)
@BijouBakson3 жыл бұрын
Thank you.
@jfversluis3 жыл бұрын
Thanks for watching!
@dolphinsoft_Youtube3 жыл бұрын
perfect
@jfversluis3 жыл бұрын
Thanks!
@hrishikeshgarud71773 жыл бұрын
Nice website.
@jfversluis3 жыл бұрын
Glad you like it!
@MrBigdogtim693 жыл бұрын
Does it make sense to declare properties with the ? operator? For example, public class foo{ public string bar? {get; set; } }. If so - how do you assign to bar?
@jfversluis3 жыл бұрын
Great question Tim! And in fact this doesn't really have much to do with the thing I'm showing here. It is somewhat related. By declaring a member like that you make it nullable when it usually isn't. Like in your example, a string gets assigned the default value. In the case of a string the default value is null already though because it’s a reference type. But for value types it will have a default value. By adding the question mark, it now is nullable, so the default value will be null and you can assign null to it. To be honest I don't find myself needing it that often, but it comes in handy sometimes. Have you used it? More info here: docs.microsoft.com/dotnet/csharp/language-reference/builtin-types/nullable-value-types
@--Eric--3 жыл бұрын
@Tim Belvin Probably a copy/paste error but the '?' goes on the type, not on the variable name. 'string? bar' The '?' has nothing to do with `how´ you set a variable, it only adds a value (null) you are allowed to use. valid 'int' values: -2147483648,...,-2,-1,0,1,2,...,2147483647 valid 'int?' values: -2147483648,...,-2,-1,0,1,2,...,2147483647 and null 'string' is only allowed to have 0-length strings "", up to n-length "..." 'string?" can besides the above x-length strings also be set to null It's up to you if you want to have this extra null-value to use for some non existent value or error etc. It may be a different thing for you if bar is "" or null (i.e. is "" an error or not). /* The above is not strictly correct, it's possible to get around, but this is the spirit of '?' nullable value types. */
@jfversluis3 жыл бұрын
@@--Eric-- Ah you're right :) my answer only makes sense if it goes on the type not the variable name. Overlooked that the first time