Convert.ToUInt16 Method in C#


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

Updated on: 22-Jun-2020

159 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements