I guess that could be considered a class in a command-based architecture, where ReadTextFile inherits from (or implements) some sort of base Command class and it contains all the information the processing system needs to perform that action, but it's a stretch, and certainly not to be taught as "the norm"...
Mark Quennell
Posts
-
OOP and the scope of a class, am I wrong? -
Really uSoft?Other than now using 64-bit, isn't that all VS2022 preview has changed so far?
-
C Sharps - how are you getting on with nullable reference types?Yeah, the Value and HasValue properties are possible for nullable value types, because they are implemented by wrapping the value type in a `Nullable`. Nullable reference types is just a compiler warning wave telling you when a reference type is null and shouldn't be, etc. The thing to remember is that StreamReader#ReadLine could always return null. The difference is that it now makes it clear by telling you "I return string?", as opposed to returning string and you not realising.
-
C Sharps - how are you getting on with nullable reference types?It depends on which version of C# you're using. In NET5 (or maybe even Core3.1), StreamReader#ReadLine does return string?. All of the core library is now annotated with ? and attributes which assist the NRT parser. You'll find this a lot in reflection and other methods which used to potentially return null.
-
C Sharps - how are you getting on with nullable reference types?Bear in mind that this is a compiler-only thing - once compiled, all strings are back to being normally nullable. If you have function declaration: `void M(string s) { }`, the idea is that you can be assured that `s` is going to be a not-null string. Because, where you call that function, you will be warned if you try `M(null)`, or ``` string? s; M(s); ``` The only times you are expected to test for null are: 1) If you receive a string? from a function. You should check for non-null before you use it. 2) Even if you have a not-null string parameter, if that method is external facing, another project may still send a null string (obviously this all works for any reference type, not just strings...) Does that help?
-
C Sharps - how are you getting on with nullable reference types?The way I see it, if you've turned on NRT, haven't got any strings with ? at the end, and no compiler errors, you're doing well :-) I use NRT all the time, since it was in the prototype stages, and I love it. The ability for the compiler to warn when you're accidentally using something that is potentially null is really useful. Especially things that you didn't previously realise could return null!