How to add ASCII value of string into array of bytes in C#

1 Answer

0 votes
using System;
using System.Text;
 
class Program
{
    static void Main() {
        string s = "c# programming";
        
        byte[] ascii = Encoding.ASCII.GetBytes(s);
         
        foreach (var b in ascii) {
            Console.Write(b + " ");
        }
    }
}
 
 
 
/*
run:
 
99 35 32 112 114 111 103 114 97 109 109 105 110 103 
 
*/

 



answered Apr 2, 2021 by avibootz
...