tagged [nullable]
How do I specify "any non-nullable type" as a generic type parameter constraint?
How do I specify "any non-nullable type" as a generic type parameter constraint? The post is specific to C# 8. Let's assume I want to have this method: If my `.csproj` looks like this (i.e. C# 8 and n...
- Modified
- 24 Apr at 20:8
Cast object to decimal? (nullable decimal)
Cast object to decimal? (nullable decimal) If have this in the setter of a property: value = "90" But after the cast, temp is ... What is the proper way to do this cast?
Correct way to check if a type is Nullable
Correct way to check if a type is Nullable In order to check if a `Type` ( `propertyType` ) is nullable, I'm using: ``` bool isNullable = "Nullable`1".Equals(propertyType.Name) ``` Is there some way t...
How will a C# switch statement's default label handle a nullable enum?
How will a C# switch statement's default label handle a nullable enum? How will a C# switch statement's default label handle a nullable enum? Will the default label catch nulls and any unhandled cases...
- Modified
- 19 Feb at 05:33
How can I convert decimal? to decimal
How can I convert decimal? to decimal may be it is a simple question but I'm try all of conversion method! and it still has error! would you help me? decimal? (nullable decimal) to decimal
- Modified
- 2 Feb at 08:10
Detecting a Nullable Type via reflection
Detecting a Nullable Type via reflection Surprisingly the following code fails the Assert: So just out curiosity, how can you determine if a given instance is a Nullable object or not?
- Modified
- 17 May at 05:58
Why don't I get a warning about possible dereference of a null in C# 8 with a class member of a struct?
Why don't I get a warning about possible dereference of a null in C# 8 with a class member of a struct? In a C# 8 project with [nullable reference types](https://learn.microsoft.com/en-us/dotnet/cshar...
- Modified
- 10 Apr at 21:44
c# why can't a nullable int be assigned null as a value
c# why can't a nullable int be assigned null as a value Explain why a nullable int can't be assigned the value of null e.g What's wrong with that code?
What is the memory footprint of a Nullable<T>
What is the memory footprint of a Nullable An `int` (`Int32`) has a memory footprint of 4 bytes. But what is the memory footprint of: and : Is this in general or type dependent?
C# struct, how to assign a null value?
C# struct, how to assign a null value? I have a list: For some reason, it is not allowing me to assign null values to it. What do I do if I want to have no struct associated?
Why int can't be null? How does nullable int (int?) work in C#?
Why int can't be null? How does nullable int (int?) work in C#? I am new to C# and just learned that objects can be null in C# but `int` can't. Also how does nullable int (`int?`) work in C#?
Cannot implicitly convert type bool?
Cannot implicitly convert type bool? I am trying to convert my nullable bool value and I am getting this error.
Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and <null>
Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and Why does this not compile? > Type of conditional expression cannot be determined because t...
Checking if Type instance is a nullable enum in C#
Checking if Type instance is a nullable enum in C# How do i check if a Type is a nullable enum in C# something like
Nullable DateTime?
Nullable DateTime? how to create setter and getter Properties for nullable datetime. for example: Does nullable attributes support setter and getter or have i to declare it public?
Best practice for using Nullable Reference Types for DTOs
Best practice for using Nullable Reference Types for DTOs I have a DTO which is populated by reading from a DynamoDB table. Say it looks like this currently: ``` public class Item { public string Id...
- Modified
- 20 Dec at 14:29
Returning nullable string types
Returning nullable string types So I have something like this which doesn't compile. How do I return a nullable string type?
Variable type ending with ?
Variable type ending with ? What does `?` mean: When applied to `string?`, there is an error: > The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic t...
Get short date for System Nullable datetime (datetime ?) in C#
Get short date for System Nullable datetime (datetime ?) in C# How to get short date for Get short date for `System Nullable datetime (datetime ?)` for ed `12/31/2013 12:00:00` --> only should return ...
WPF Textbox accept INT but not NULLABLE INT?
WPF Textbox accept INT but not NULLABLE INT? Model XAML Once user try to or the value in this `textbox`, a message `Value '' cannot be converted`. May I know what's wrong with it?
Is constructor the only way to initialize non-nullable properties in a class in C#?
Is constructor the only way to initialize non-nullable properties in a class in C#? I have switched to enable nullable in my project that uses C#8. Now I have the following class: Compiler of course c...
- Modified
- 27 Nov at 13:6
What is the use of Nullable<bool> type?
What is the use of Nullable type? a variable could hold true or false, while could be null as well. Why would we need a third value for bool ? If it is not , what ever it is, it is == Can you suggest ...
How to convert C# nullable int to int
How to convert C# nullable int to int How do I convert a nullable `int` to an `int`? Suppose I have 2 type of int as below: I want to assign `v1`'s value to `v2`. `v2 = v1;` will cause an error. How d...
Why nullable int (int?) doesn't increase the value via "+=" if the value is NULL?
Why nullable int (int?) doesn't increase the value via "+=" if the value is NULL? I have a page counter type of int?: It works ONLY if the value of ViewCount property is (any int). Why the compiler do...
- Modified
- 30 Jul at 09:53