public virtual int Fill(DataSetservices.Jobs_detailsDataTable dataTable,
global::System.Nullable<global::System.String> fromdate,
global::System.Nullable<global::System.DateTime> todate)
I wrote above code in dataset.xsd
in C#, but it is throwing an error:
Error 1
The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'
Suggest me how to use string because i want to use string and nothing else
The nullable type can only be used with value types and not with reference types. So, we cannot use nullable with string.
Nullable variables may either contain a valid value or they may not — in the latter case they are considered to be nil . Non-nullable variables must always contain a value and cannot be nil . In Oxygene (as in C# and Java), the default nullability of a variable is determined by its type.
The only way to create a non-nullable type is to declare a struct - structs, however, cannot inherit or be inherited from. Using properties as you are is most likely the best way, or null-coalescing during deserialization as previously suggested, but C# is simply designed to handle null values.
You typically use a nullable value type when you need to represent the undefined value of an underlying value type. For example, a Boolean, or bool , variable can only be either true or false .
string
is already nullable, because it's a reference type. You don't need to wrap it in Nullable
in order to have a null value. Not only is it not needed, but as per the error message you're getting, it's not even possible. Only non-nullable value types can be used as the generic argument for Nullable
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With