
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- How do you declare jagged arrays in C#
- Compare two char arrays in a single line in Java
- Java Program to compare two Java char Arrays
- How do you declare, initialize and access jagged arrays in C#?
- Difference between char s[] and char *s in C
- Difference between const char* p, char * const p, and const char * const p in C
- Char Struct in C#
- How to convert an std::string to const char* or char* in C++?
- How to convert a std::string to const char* or char* in C++?
- Char.ToUpperInvariant(Char) Method in C#
- Char.ToLowerInvariant(Char) Method in C#
- Uri.HexEscape(Char) Method in C#
- CHAR vs VARCHAR in SQL
- char vs string keywords in C#
- Declare dynamically in SAP ABAP

Advertisements