How to copy N characters from char array into another array in C#

1 Answer

0 votes
using System;

// Array.Copy(Array, Int32, Array, Int32, Int32)

public class Example
{
	public static void Main(string[] args) {

		char[] formArray = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'k', 'l'};
		
		int N = 3;
		char[] toArray = new char[N];

		Array.Copy(formArray, 2, toArray, 0, N);

		foreach (char ch in toArray) {
			Console.WriteLine(ch);
		}
	}
}




/*
run:
  
c
d
e
  
*/

 



answered Aug 15, 2022 by avibootz

Related questions

1 answer 233 views
1 answer 229 views
1 answer 169 views
169 views asked Aug 15, 2022 by avibootz
1 answer 181 views
2 answers 207 views
207 views asked Aug 15, 2022 by avibootz
1 answer 163 views
...