C
C#9mo 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
Angius9mo ago
Makes the property required Unconditionally If you're fine with a default value, make it not required (also, make it a property)
cheeze2000
cheeze2000OP9mo ago
by property, you mean the get set stuff?
Angius
Angius9mo ago
Yes The general rule of thumb is "if it's public, it should be a property"
cheeze2000
cheeze2000OP9mo ago
oh i see then what should i be using members?
Angius
Angius9mo ago
Fields are usually private If that's what you mean by "member" $structure
MODiX
MODiX9mo 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
Angius9mo ago
Here's most of the naming
cheeze2000
cheeze2000OP9mo ago
nice thanks
Want results from more Discord servers?
Add your server