Convert.ToUInt16 Method in C#

ProgrammingServer Side ProgrammingCsharp

Use the Convert.ToUInt16 method to convert a specified value to a 16-bit unsigned integer.

Here is our string −

string str = "1129";

Now let us convert it to 16-bit unsigned integer.

ushort res;
res = Convert.ToUInt16(str);

The following is the complete example −

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      string str = "1307";
      ushort res;
      res = Convert.ToUInt16(str);
      Console.WriteLine("Converted string '{0}' to {1}", str, res);
   }
}

Output

Converted string '1307' to 1307
raja
Published on 11-Sep-2018 12:40:11
Advertisements