C
C#8mo ago
cheeze2000

✅ Don't quite understand the `required` keyword

although i marked the member as required, i defined a default value in case if it's not in the object initializer. does the keyword not work this way?
No description
8 Replies
Angius
Angius8mo ago
Makes the property required Unconditionally If you're fine with a default value, make it not required (also, make it a property)
cheeze2000
cheeze2000OP8mo ago
by property, you mean the get set stuff?
Angius
Angius8mo ago
Yes The general rule of thumb is "if it's public, it should be a property"
cheeze2000
cheeze2000OP8mo ago
oh i see then what should i be using members?
Angius
Angius8mo ago
Fields are usually private If that's what you mean by "member" $structure
MODiX
MODiX8mo ago
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
Angius
Angius8mo ago
Here's most of the naming
cheeze2000
cheeze2000OP8mo ago
nice thanks
Want results from more Discord servers?
Add your server