

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is it possible to resize an array in C#
You cannot resize an array in C#, but using Array.Resize you can replace the array with a new array of different size.
The following is our array −
char[] ch = new char[10]; ch[0] = 'a'; ch[1] = 'b';
Now, resize −
Array.Resize<char>(ref ch, 10);
The following is the complete example −
Example
using System; class Program { static void Main() { char[] ch = new char[10]; ch[0] = 'a'; ch[1] = 'b'; // Resize array Array.Resize<char>(ref ch, 10); // Set value for new elements ch[2] = 'c'; ch[3] = 'd'; ch[4] = 'e'; ch[5] = 'f'; ch[6] = 'g'; ch[7] = 'h'; ch[8] = 'i'; ch[9] = 'j'; Console.WriteLine("New Array: "+ new string(ch)); } }
Output
New Array: abcdefghij
- Related Questions & Answers
- Is it possible to override toString method in an array using Java?
- How to resize an array in Java?
- Check if it is possible to sort the array after rotating it in Python
- Is it possible to assign a numeric value to an enum in Java?
- Check if it is possible to sort an array with conditional swapping of adjacent allowed in Python
- Is it possible to make an insert or an update in the same MySQL query?
- Is it possible to style HTML5 audio tag?
- Is it possible to use MongoDB capped collection?
- Is it possible to control Matplotlib marker orientation?
- Is it possible to use pyplot without DISPLAY?
- Is it possible to use Python modules in Octave?
- Is it possible to cast in a MongoDB Query?
- Is it possible to create static constructor in java?
- Is it possible to change values of the array when doing foreach() in javascript?
- How to resize an Image C#?
Advertisements