Click here to Skip to main content
15,890,825 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to tell whether a string is a number? Pin
clarkwuzhe5-Feb-03 11:39
clarkwuzhe5-Feb-03 11:39 
GeneralRe: How to tell whether a string is a number? Pin
Paresh Gheewala5-Feb-03 11:42
Paresh Gheewala5-Feb-03 11:42 
GeneralRe: How to tell whether a string is a number? Pin
Paresh Gheewala5-Feb-03 11:45
Paresh Gheewala5-Feb-03 11:45 
GeneralRe: How to tell whether a string is a number? Pin
clarkwuzhe5-Feb-03 11:46
clarkwuzhe5-Feb-03 11:46 
GeneralRe: How to tell whether a string is a number? Pin
Paresh Gheewala5-Feb-03 11:51
Paresh Gheewala5-Feb-03 11:51 
AnswerRe: How to tell whether a string is a number? Pin
Vasudevan Deepak Kumar5-Feb-03 17:53
Vasudevan Deepak Kumar5-Feb-03 17:53 
AnswerRe: How to tell whether a string is a number? Pin
Ian Darling5-Feb-03 23:04
Ian Darling5-Feb-03 23:04 
AnswerRe: How to tell whether a string is a number? Pin
Richard Deeming6-Feb-03 0:33
mveRichard Deeming6-Feb-03 0:33 
Here's the C# equivalent of VBs IsNumeric function:
using System;
using System.Globalization;
 
public class Conversion
{
    private static bool IsNumericTypeCode(TypeCode t) 
    {
        switch (t) 
        {
            case TypeCode.Boolean:
            case TypeCode.Byte:
            case TypeCode.SByte:
            case TypeCode.Int16:
            case TypeCode.UInt16:
            case TypeCode.Int32:
            case TypeCode.UInt32:
            case TypeCode.Int64:
            case TypeCode.UInt64:
            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.Decimal:
                return true;
    
            default:
                return false;
        }
    }
    
    public static bool IsNumeric(object expression) 
    {
        string sExp = null;
        IConvertible conv = expression as IConvertible;
        if (null == conv)
        {
            if (null == expression as char[]) 
                return false;
            
            sExp = new string((char[])expression);
        }
        else 
        {
            TypeCode t = conv.GetTypeCode();
            if (IsNumericTypeCode(t)) 
                return true;
            else if (t == TypeCode.String || t == TypeCode.Char) 
                sExp = conv.ToString(null);
        }
        
        if (null == sExp)
            return false;
        else 
            return IsNumeric(sExp);
    }
    
    public static bool IsNumeric(string expression) 
    {
        if (null == expression || 0 == expression.Length) 
            return false;
        else 
        {
            double d;
            return double.TryParse(expression,
                NumberStyles.Any, null, out d);
        }
    }
}



"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
GeneralRe: How to tell whether a string is a number? Pin
Vasudevan Deepak Kumar6-Feb-03 2:22
Vasudevan Deepak Kumar6-Feb-03 2:22 
GeneralRe: How to tell whether a string is a number? Pin
Richard Deeming6-Feb-03 2:33
mveRichard Deeming6-Feb-03 2:33 
GeneralRe: How to tell whether a string is a number? Pin
Vasudevan Deepak Kumar7-Feb-03 0:11
Vasudevan Deepak Kumar7-Feb-03 0:11 
GeneralRe: How to tell whether a string is a number? Pin
Richard Deeming7-Feb-03 0:15
mveRichard Deeming7-Feb-03 0:15 
GeneralTabbing MDI childs Pin
thedex5-Feb-03 11:11
thedex5-Feb-03 11:11 
GeneralRe: Tabbing MDI childs Pin
Vasudevan Deepak Kumar6-Feb-03 2:29
Vasudevan Deepak Kumar6-Feb-03 2:29 
QuestionHow to create a control that docks and slides like the toolbox? Pin
thedex5-Feb-03 11:06
thedex5-Feb-03 11:06 
AnswerRe: How to create a control that docks and slides like the toolbox? Pin
Chris Austin5-Feb-03 13:13
Chris Austin5-Feb-03 13:13 
QuestionDateTimePicker Color Change? Pin
Sovman5-Feb-03 10:42
Sovman5-Feb-03 10:42 
AnswerRe: DateTimePicker Color Change? Pin
TigerNinja_6-Feb-03 3:55
TigerNinja_6-Feb-03 3:55 
GeneralBuilding a .NET User Control base Class Pin
Anonymous5-Feb-03 7:46
Anonymous5-Feb-03 7:46 
GeneralRe: Building a .NET User Control base Class Pin
TigerNinja_5-Feb-03 8:28
TigerNinja_5-Feb-03 8:28 
GeneralRe: Building a .NET User Control base Class Pin
leppie5-Feb-03 9:07
leppie5-Feb-03 9:07 
GeneralRe: Building a .NET User Control base Class Pin
FruitBatInShades5-Feb-03 10:43
FruitBatInShades5-Feb-03 10:43 
GeneralDeserialization problem Pin
Roman Shchugarev5-Feb-03 1:43
Roman Shchugarev5-Feb-03 1:43 
GeneralRe: Deserialization problem Pin
marcossl5-Feb-03 7:02
marcossl5-Feb-03 7:02 
GeneralRe: Deserialization problem Pin
Roman Shchugarev5-Feb-03 19:41
Roman Shchugarev5-Feb-03 19:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.