Blog Stats
  • Posts - 170
  • Articles - 4
  • Comments - 54
  • Trackbacks - 7

 

Some VB commands adapted for C#

1. Porting Common VB functions to C#: isNumeric()

bool isNumeric(char ch)
{
    //If the given character is in between 0 and 9 then
    //return true, otherwise false
    if (ch >= '0' && ch <= '9')
        return true;
    else
        return false;
}
 

2. Porting Common VB functions to C#: Asc()

int Asc(char ch)
{
    //Return the character value of the given character
    return (int)Encoding.ASCII.GetBytes(S)[0];
}
 
3. Porting Common VB functions to C#: Chr()

Char Chr(int i)
{
    //Return the character of the given character value
    return Convert.ToChar(i);
}
 
4. Porting Common functions to C#: isLower()

bool isLower(char ch)
{
    //If the given character is in between a and z then
    //return true, otherwise false
    if (ch >= 'a' && ch <= 'z')
        return true;
    else
        return false;
}

The same function can also be written as more .NET frieldly:

bool isLower(char ch)
{
    return Char.IsLower(ch));
}
 
5. Porting Common functions to C#: isUpper()

bool isUpper(char ch)
{
    //If the given character is in between A and Z then
    //return true, otherwise false
    if (ch >= 'A' && ch <= 'Z')
        return true;
    else
        return false;
}

The same function can also be written as:

bool isUpper(char ch)
{
    return Char.IsUpper(ch));
}


Feedback

# re: Some VB commands adapted for C#

Gravatar I personally like to reduce down my if statements, even though they're probably reduced during compiler optimisation anyway...

bool isNumeric(char ch) {
return (ch >= '0' && ch <= '9');
} 4/15/2005 1:57 PM | Jamie Plenderleith

# re: Some VB commands adapted for C#

Gravatar Thanks for posting these. Very helpful! 10/11/2005 10:26 PM | Mike

# re: Some VB commands adapted for C#

Gravatar Example 1 exists in C# as

char.IsNumber(char); 4/28/2006 10:53 PM | TLL

Comments have been closed on this topic.
 

 

Copyright © Paschal L