How to extract the first five characters from a string into an array with C#

1 Answer

0 votes
using System;
using System.Linq;
 
class Program
{
   static void Main() {
        string s = "c#-programming";
         
        char[] array = s.Take(5).ToArray();
 
        Console.WriteLine(array);
        Console.WriteLine(s);
    }
}
 
 
 
 
/*
run:
 
c#-pr
c#-programming
 
*/

 



answered Jun 8, 2021 by avibootz

Related questions

1 answer 150 views
1 answer 213 views
1 answer 136 views
1 answer 119 views
...