C# | Char.GetNumericValue() Method - GeeksforGeeks

01 Feb, 2019
In C#, Char.GetNumericValue() is a System.Char struct method which is used to convert a numeric Unicode character into a double-precision floating-point number. The numeric value must belong to UnicodeCategory, i.e DecimalDigitNumber, LetterNumber, or OtherNumber. This method can be overloaded by passing different type and number of arguments to it.
Char.GetNumericValue(String, Int32) MethodChar.GetNumericValue(Char) Method
Char.GetNumericValue(String, Int32) Method
Char.GetNumericValue(Char) Method
This method is used to convert the numeric Unicode character at the specified position in a specified string to a double-precision floating point number. Character position in a string always starts from zero.
Syntax:
public static double GetNumericValue(String str, int index);
Parameters:
str: It is the specified string of type System.String.
index: It represents the character position in the string str and type of this parameter is System.Int32.
Return Type: If the character is represented by the number, then this method returns a numeric value at position index in str otherwise it returns -1. The return type of this method is System.Double.
Exceptions:
If the value of the given string str is null then this method will give ArgumentNullException.
If the index is less than zero or greater than the last position in str, then this method will give ArgumentOutOfRangeException.
Example:
// C# program to illustrate the// Char.GetNumericValue(String, Int32) Methodusing System;  class GeeksforGeeks {      // Main method    public static void Main()    {          // declaration of datatype        double output;        string str = "geeks213";          // provide numeric value of position 4        output = Char.GetNumericValue(str, 4);        Console.WriteLine(output);          // provide numeric value of position 7        output = Char.GetNumericValue(str, 7);        Console.WriteLine(output);    }}
-1
3

This method is used to convert the specified Unicode character into a double-precision floating-point number.
Syntax:
public static double GetNumericValue(Char ch);
Parameter:
ch: It is the Unicode character which is to be converted into double-precision floating-point number.
Return Type: If a character represents a number, then this method returns the numeric value of ch, otherwise it returns -1.0. The return type of this method is System.Double.
Example:
// C# program to illustrate the// Char.GetNumericValue(Char) Methodusing System;  class GeeksforGeeks {          // Main method    public static void Main()    {                  // using Char.GetNumericValue(char method)        Console.WriteLine(Char.GetNumericValue('9'));        Console.WriteLine(Char.GetNumericValue('z'));    }}
9
-1

Reference: https://docs.microsoft.com/en-us/dotnet/api/system.char.getnumericvalue?view=netframework-4.7.2
CSharp-Char-Struct
CSharp-method
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between Abstract Class and Interface in C#
String.Split() Method in C# with Examples
C# | How to check whether a List contains a specified element
C# | IsNullOrEmpty() Method
C# Dictionary with examples
C# | Arrays of Strings
C# | Delegates
C# | Method Overriding
C# | Abstract Classes
Difference between Ref and Out keywords in C#