nullable Questions
2
Since C# 8.0, the standard is non nullable variable by default. Ref1
But in case of generics like this one:
public static T PerfomIO<T>(Func<T> function, T defaultValue = default)
{
...
Corbitt asked 6/4, 2021 at 17:56
4
Solved
How will a C# switch statement's default label handle a nullable enum?
Will the default label catch nulls and any unhandled cases?
Dyspepsia asked 19/2, 2013 at 5:33
1
Solved
I've come across the following phenomenon and am absolutely bamboozled. I'm using C# 10 with nullables enabled.
default(int?) returns null as expected. The following function, however, returns what...
Roomy asked 30/5, 2022 at 13:3
1
Solved
I'm getting to grips with the nullable change, but I've hit something that's giving CS8618 (Nullable field must contain non-null) but I don't think it should be.
Basically I have a private field, a...
2
Solved
I'm creating a new table, like this:
<createTable tableName="myTable">
<column name="key" type="int" autoIncrement="true">
<constraints primaryKey="true" primaryKeyName="PK_myTab...
21
Solved
How can I convert the nullable DateTime dt2 to a formatted string?
DateTime dt = DateTime.Now;
Console.WriteLine(dt.ToString("yyyy-MM-dd hh:mm:ss")); //works
DateTime? dt2 = DateTime.Now;
Console...
Jamajamaal asked 2/12, 2009 at 13:57
9
Solved
I have an enum
string name;
public enum Color
{
Red,
Green,
Yellow
}
How to set it to NULL on load.
name = "";
Color color = null; //error
Edited:
My bad, I didn't explain it properly. B...
2
When using the new Scala 3's flag -Yexplicit-nulls, every Java code which doesn't have explicit non-null annotations is treated as nullable, thus every Java method not returning a primitive type T ...
3
Solved
For example, if I have the following data class:
data class Data(
val name: String = "",
val number: Long = 0
)
And functions that can return null:
fun newName(): String? {}
fun newNumber():...
Puff asked 23/6, 2017 at 19:15
4
I'm struggling to do table driven test, and I want do this:
testCases := []struct {
name string
testUserID uint
expected User // <- maybe nil
expectedError error
}
Because the return valu...
10
Solved
I want use @Nullable annotation to eliminate NullPointerExceptions.
I found some tutorials on the net, I noticed that this annotation comes from the package javax.annotation.Nullable;
but when I im...
Cystotomy asked 26/9, 2013 at 14:25
5
Solved
I'm using OpenApi SpringBoot generator to generate controller interfaces and models. This creates model classes with JsonNullable<String> for nullable fields. However I'm getting a Jackson ty...
Pyroclastic asked 30/12, 2019 at 0:6
2
Solved
I am using C# 8.0 with NullableContextOptions (Nullable Reference) enabled.
I have a function with this signature:
public static (int line, string content)? GetNextNonEmptyLineDown(this IList<...
Gerek asked 2/3, 2019 at 18:23
1
Solved
How can I tell compiler that the following extension method returns not null if input is not null?
public static string? SomeMethod(this string? input)
{
if (string.IsNullOrEmpty(input))
return i...
Creamcups asked 13/3, 2022 at 19:19
1
Solved
IntelliJ is showing me context hints that my variables are of type (String..String?). I cannot find any mention of it on the internet, what is this type?
Accouchement asked 12/2, 2022 at 20:4
3
Consider the following code:
function Test
{
[CmdletBinding()]
param
(
[parameter(Mandatory=$true)]
[AllowNull()]
[String]
$ComputerName
)
process{}
}
Test -ComputerName $null
Based o...
Agnesse asked 5/8, 2015 at 21:49
3
I need to define a System.Data.DataTable in C# VS2013; in one column, it may be int or null.
But I got:
DataSet does not support System.Nullable<>.
For the definition:
public DataTable myDa...
10
Solved
I'm serializing a class like this
public MyClass
{
public int? a { get; set; }
public int? b { get; set; }
public int? c { get; set; }
}
All of the types are nullable because I want minimal d...
Kensell asked 7/10, 2009 at 18:24
2
In class Microsoft.Net.Http.Headers.ContentRangeHeaderValue, there is a nullable value type property (long?) that is decorated with a NotNullIfNotNull attribute referencing itself (property Length)...
Destroy asked 11/1, 2022 at 23:14
3
Solved
I'm having one null-able bool (bool?) variable, it holds a value null. One more variable of type pure bool, I tried to convert the null-able bool to bool. But I faced an error "Nullable object must...
1
Solved
ReadFromJsonAsync method returns nullable T. Here is a code sample:
private async Task<T> Get<T>(Uri url, CancellationToken cancellationToken)
{
using HttpResponseMessage response = aw...
5
According to the official kotlin documentation, the toString() call of a null object returns "null" toString()
I want, that toString() should return an empty string ("") instead. I implemented it ...
1
Solved
Consider an example:
class Test {
string S { get; set; }
public Test() {
Init();
}
private void Init() {
S = "hello";
}
}
Using nullable C# project feature, this sample will ...
5
Solved
I'm doing a projection in this method:
public async Task<TradeDetail> Get(int tradeId)
{
var firstOrDefaultAsync = await context.EvgTGTrade
.Where(x => x.IdTrade == tradeId)
.Select(tra...
Gentille asked 22/1, 2020 at 16:20
1
Solved
Given the following generic Foo1 function:
struct Key<T> {}
static readonly Key<double> MyKey = new Key<double>();
T? Foo1<T>(Key<T> key)
{
return default;
}
A naive...
© 2022 - 2024 — McMap. All rights reserved.