Languages
[Edit]
EN

C#/.NET - convert string to short

3 points
Created by:
Kelly
394

In C#/.NET string can be parsed to short in few ways.

1. short.Parse method example

Edit

Output:

2. short.TryParse method example

Edit

Output:

3. Convert.ToInt16 method example

Edit

Output:

4. TypeConverter.ConvertFrom method example

Edit

Output:

5. Custom conversion example

Edit

Check this article

6. Notes

Edit
The following methods short.Parse, short.TryParse, Convert.ToInt16 and TypeConverter.ConvertFrom throw System.FormatException.

7. References

Edit
  1. short.Parse(String) - Microsoft Docs
  2. short.TryParse(String, Int16) - Microsoft Docs
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join