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

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.