What is the equivalent to Java's string.getBytes() in C#?
c#, java
Solution
Encoding.GetBytes
http://msdn.microsoft.com/en-us/library/system.text.encoding.getbytes.aspx
byte[] bytes = Encoding.ASCII.GetBytes("Sweet!");
Problem
Possible Duplicate: Equivalent of getBytes() in Java to C# In Java: ``` String s="abcde"; byte bar[] = s.getBytes(); ``` In C#: ``` for (int i = 0; i < s.Length; i++) { bar[i] = Convert.ToByte(s.Substring(i, 1)); } ``` I worked Java example getBytes to convert C# code. But the above C# code does not work.