在同一行声明的多个字段的可访问性
Accessibility of multiple fields declared at the same line
我想知道我是否这样做所有变量都将是 public 或只是第一个:
public string equipamento, marca, modelo, descricao, observacoes, prioridade;
或者如果我需要这样声明它们:
public string equipamento;
public string marca;
public string modelo;
[...]
第二个选项显然有效,但第一个也有效吗?
如 C# 语言规范第 10.4 节字段中所述on MSDN:
A field declaration that declares multiple fields is equivalent to multiple declarations of single fields with the same attributes, modifiers, and type. For example
class A
{
public static int X = 1, Y, Z = 100;
}
is equivalent to
class A
{
public static int X = 1;
public static int Y;
public static int Z = 100;
}
但作为,请考虑以前的不良做法。它会严重损害代码的可读性。
我想知道我是否这样做所有变量都将是 public 或只是第一个:
public string equipamento, marca, modelo, descricao, observacoes, prioridade;
或者如果我需要这样声明它们:
public string equipamento;
public string marca;
public string modelo;
[...]
第二个选项显然有效,但第一个也有效吗?
如 C# 语言规范第 10.4 节字段中所述on MSDN:
A field declaration that declares multiple fields is equivalent to multiple declarations of single fields with the same attributes, modifiers, and type. For example
class A { public static int X = 1, Y, Z = 100; }
is equivalent to
class A { public static int X = 1; public static int Y; public static int Z = 100; }
但作为