C
C#3y ago
Thinker

Default struct with default value [Answered]

I have this struct
public readonly struct RuntimeConfiguration
{
public int MaxLineCount { get; init; } = 10_000;



public RuntimeConfiguration()
{
}
}
public readonly struct RuntimeConfiguration
{
public int MaxLineCount { get; init; } = 10_000;



public RuntimeConfiguration()
{
}
}
I also have a method which takes a parameter RuntimeConfiguration configuration = default, yet this default instance does not have MaxLineCount set to the value 10000? Does default only initialize the struct with every field to its type's default value, and not any user-provided default value?
2 Replies
Thinker
ThinkerOP3y ago
And also, is there a better way to do this to actually have a default value? nvm, can just use RuntimeConfiguration? configuration = null and then do configuration ?? new()
Accord
Accord3y ago
✅ This post has been marked as answered!

Did you find this page helpful?