Home » .Net

char structure and its methods in C#

Learn: char structure and its methods in C#.net, it’s a predefined structure, which has some methods and properties. Here we are going to learn about char structure.

char is a pre-define structure of .NET framework class library. And as we know that every structure in .NET framework contains some methods and properties to operate on it.

There are following important methods of char structure:

  1. char.Parse()
  2. char.Equals()
  3. char.IsDigit()
  4. char.IsLetter()
  5. char.IsSeparator()
  6. char.IsLower()
  7. char.IsUpper()

1) char.Parse()

This method is used to convert or parse string to char.

2) char.Equals

This method is used to check two given character object are equal or not. It returns boolean result.

3) char.IsDigit()

This method is used to check given character object is digit or not. It returns Boolean result.

4) char.IsLetter()

This method is used to check given character object is letter or not. It returns Boolean result.

5) char.IsSeparator()

This method is used to check given character object is separator or not. It returns Boolean result.

6) char.IsLower()

This method is used to check given character object is in lower case or not. It returns Boolean result.

7) char.IsUpper()

This method is used to check given character object is in upper case or not. It returns Boolean result.

All above method can easily understand with the help of program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            bool flag = false;
            char val;

            val = char.Parse("A");

            Console.WriteLine("Value is : "+val);

            flag = char.Equals('A','A');

            if(flag == true)
                Console.WriteLine("Both are equal");
            else
                Console.WriteLine("Both are not equal");

            flag = char.IsDigit('A');
            
            if(flag == true)
                Console.WriteLine("Given character is digit");
            else
                Console.WriteLine("Given character is not digit");

            flag = char.IsLetter('A');
            if(flag == true)
                Console.WriteLine("Given character is letter");
            else
                Console.WriteLine("Given character is not letter");

            flag = char.IsLower('a');
            if(flag == true)
                Console.WriteLine("Given character is in lowercase");
            else
                Console.WriteLine("Given character is not in lowercase");

            flag = char.IsUpper('a');
            if(flag == true)
                Console.WriteLine("Given character is in uppercase");
            else
                Console.WriteLine("Given character is not in uppercase");


        }
    }
}

Above program produce following result:

Output

Value is : A
Both are equal
Given character is not digit
Given character is letter
Given character is in lowercase
Given character is not in uppercase


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.