I have a function that returns MemoryStream?. Therefore, null if an error occurs. Then I found that I could not declare a variableMemoryStream?
MemoryStream?
public MemoryStream? GetResponseStream() { } MemoryStream? stream = GetResponseStream();
The type "System.IO.MemoryStream" must be an unimaginable value type in order to use it as the "T" parameter in the generic type or method "System.Nullable"
MemoryStream ( class) . ( struct) NULL, ?.
class
struct
?
, :
public MemoryStream GetResponseStream() { ... }
:
MemoryStream stream = GetResponseStream(); if (stream == null) { ... }
BTW: , , , GetResponseStream null.
GetResponseStream
null
MemoryStream , . Nullable<T> , .
MemoryStream
Nullable<T>
, . A MemoryStream , .
No need ?, as reference types can be null.
public MemoryStream GetResponseStream() { return(null); }
A modifier with a zero value (?) Is used only for value types. A stream is a type of object that can always be set to null (by its nature, it is already "nullified"). Therefore, you do not need to do what you are trying to do.
Source: https://habr.com/ru/post/1776239/More articles:image size on Objective-c, - iphoneuse of external libraries in Qt / Symbian - qtAverage performance for local IPCs - performancePDO - get result of COUNT (*)? - phpHow to remove Hibernate @Embeddables containing nullable fields? - javaHow to add separator to Eclipse RCP toolbar? - eclipse-pluginPython code to consolidate CSS to HTML - pythonPHP: Как запустить цикл в течение определенного времени дня? - phpUsing native pointers in F # with WritableBitmap - f #Access error while accessing when opening a file in JavaScript - javascriptAll Articles