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 char arrays in C#
Declare a char array and set the size −
char[] arr = new char[5];
Now set the elements −
arr[0] = 'h'; arr[1] = 'a'; arr[2] = 'n'; arr[3] = 'k'; arr[4] = 's';
Let us see the complete code now to declare, initialize and display char arrays in C# −
Example
using System;
public class Program {
public static void Main() {
char[] arr = new char[5];
arr[0] = 'h';
arr[1] = 'a';
arr[2] = 'n';
arr[3] = 'k';
arr[4] = 's';
Console.WriteLine("Displaying string elements...");
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine(arr[i]);
}
}
}
Output
Displaying string elements... h a n k s
Advertisements
