Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Declare a const array in C#
In C#, use readonly to declare a const array.
public static readonly string[] a = { "Car", "Motorbike", "Cab" };
In readonly, you can set the value at runtime as well unlike const.
Another alternative of achieving what we saw above −
public ReadOnlyCollectiona { get { return new List { "Car", "Motorbike", "Cab" }.AsReadOnly();}}
.NET framework 4.5 brings an improvement to what we saw −
public ReadOnlyCollectiona { get; } = new ReadOnlyCollection ( new string[] { "Car", "Motorbike", "Cab" } );
Advertisements
