C
C#4mo ago
Frite

Should I be worried about it ?

CA2211 : les champs non constants ne doivent pas être visibles (ana...
En savoir plus sur la règle d’analyse du code CA2211 : les champs non constants ne doivent pas être visibles
22 Replies
Angius
Angius4mo ago
The rule of thumb is private fields public properties, yes
Frite
FriteOP4mo ago
ok but how is it more secured ?
Angius
Angius4mo ago
"Secure" as in "someone will be able to hack the user's computer"? It's not "Secure" as in "you'll be able to make changes easier without sacrificing backwards compatibility"? Yes, definitely
Frite
FriteOP4mo ago
i mean, i prevents potential bugs ? is that the point of it ?
Angius
Angius4mo ago
Potentially, yes
Frite
FriteOP4mo ago
(maybe switch my post to beginner)
Angius
Angius4mo ago
You just do With the word static public static int SomeNumber { get; set; }
Frite
FriteOP4mo ago
bruh how can i be such a noob
No description
Angius
Angius4mo ago
A static member cannot reference instance members
Frite
FriteOP4mo ago
so i make the camera instance static ?
Angius
Angius4mo ago
No I said member not class Fields, properties, methods — those are class members
Frite
FriteOP4mo ago
i mean not the class static, but i can make it a static var of an other class
Angius
Angius4mo ago
Also, you don't need to do
private int _foo = 99;
public int Foo {
get { return _foo; }
}
private int _foo = 99;
public int Foo {
get { return _foo; }
}
it can just be
public int Foo { get; } = 99;
public int Foo { get; } = 99;
$getsetdevolve
MODiX
MODiX4mo ago
class Foo
{
private int _bar;

public int GetBar()
{
return _bar;
}

public void SetBar(int bar)
{
_bar = bar;
}
}
class Foo
{
private int _bar;

public int GetBar()
{
return _bar;
}

public void SetBar(int bar)
{
_bar = bar;
}
}
can be shortened to
class Foo
{
private int _bar;

public int GetBar() => _bar;

public void SetBar(int bar) => _bar = bar;
}
class Foo
{
private int _bar;

public int GetBar() => _bar;

public void SetBar(int bar) => _bar = bar;
}
can be shortened to
class Foo
{
private int _bar;
public int Bar {
get { return _bar; }
set { _bar = value; }
}
}
class Foo
{
private int _bar;
public int Bar {
get { return _bar; }
set { _bar = value; }
}
}
can be shortened to
class Foo
{
private int _bar;
public int Bar {
get => _bar;
set => _bar = value;
}
}
class Foo
{
private int _bar;
public int Bar {
get => _bar;
set => _bar = value;
}
}
can be shortened to
class Foo
{
public int Bar { get; set; }
}
class Foo
{
public int Bar { get; set; }
}
Frite
FriteOP4mo ago
thanks guys
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX4mo 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;

int LocalMethod(string param) { return 3; }
}
}
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;

int LocalMethod(string param) { return 3; }
}
}
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Frite
FriteOP4mo ago
i have a very big info list on visualStudio
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Frite
FriteOP4mo ago
some naming rules for example or others simplifications that can be made
Want results from more Discord servers?
Add your server