a{get{returnnewList Home >
Article > Backend Development > Declare const arrays in C# In C#, use readonly to declare a const array. In readonly, unlike const, you can also set the value at runtime. An alternative way to implement the above is - .NET Framework 4.5 brings us improvements - The above is the detailed content of Declare const arrays in C#. For more information, please follow other related articles on the PHP Chinese website!Declare const arrays in C#
public static readonly string[] a = { "Car", "Motorbike", "Cab" };
public ReadOnlyCollection<string> a { get { return new List<string> { "Car", "Motorbike", "Cab" }.AsReadOnly();}}
public ReadOnlyCollection<string> a { get; } = new ReadOnlyCollection<string>(
new string[] { "Car", "Motorbike", "Cab" }
);