For instance:
public class Stereo { public Speaker? LeftSpeaker; public int? Volume; }
int?works fine, but I can't make the speaker null. It turned out to be surprisingly difficult for Google, I thought it would be easy ...
int?
Why do you need this? Obscene types (i.e. Link types) can already be set and mapped to null.
null
Adding a wrapper Nullable<T>over objects of a reference type would create two levels of zeroing; meaningless complexity, so it is not allowed.
Nullable<T>
It's simple. The non-value types are actually called .NET link types and are automatically nullified. Just change your code:
public class Stereo { public Speaker LeftSpeaker; // ? removed for ref type public int? Volume; }
Wild swag:
public class Stereo { public Speaker LeftSpeaker; public int? Volume; public Stereo() { LeftSpeaker = null; // Mission accomplished. } }
A lot of fish is already here, but if you want to learn how to fish, I suggest taking a look at the Jon Skeet book C # in depth . Chapters 4.1-4.5 discuss all aspects of the "concept of invalidity" in C #.
Source: https://habr.com/ru/post/1775655/More articles:Emacs -fs (fullscreen) - emacswho are the people devs / techies should follow on twitter / facebook? - twitterSeparating XSLT on a child of a node - xsltVisual Studio 6 cannot load the COM COM library compiled in .net 2.0 - .netUsing cons using `list` or` append` - lispРеализация основных функций библиотеки в LISP (вручную) - listRefresh / Refresh tab bar items in ViewController? - iphoneWriting SSIS Variable Variables - sqlWhen using DataTable and DataGrid in WPF System.Windows.Data Error Occurs - c #IPhone line break with i18n - iphoneAll Articles