Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
How to set ASCII Characters in MaskedTextBox in C#?
Next article icon

Convert a Character to the String in C#

Last Updated : 26 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

Given a character, the task is to character to the string in C#.

Examples:

Input :  X = 'a'  Output : string S = "a"    Input :  X = 'A'  Output : string S = "A"  

Approach: The idea is to use ToString() method, the argument is the character and it returns string converting Unicode character to the string.

// convert the character x  // to string s  public string ToString(IFormatProvider provider);  

C#




// C# program to character to the string
using System;
  
public class GFG{
      
    static string getString(char x) 
    {
        // Char.ToString() is a System.Char 
        // struct method which is used 
        // to convert the value of this
        // instance to its equivalent
        // string representation
        string str = x.ToString();
          
        return str;
    }
    
    static void Main(string[] args)
    {
        char chr = 'A';
        Console.WriteLine("Type of "+ chr +" : " + chr.GetType());
          
        string str = getString(chr);
        Console.WriteLine("Type of "+ str +" : " + str.GetType());
  
    }
}
 
 

Output:

Type of A : System.Char  Type of A : System.String  


Next Article
How to set ASCII Characters in MaskedTextBox in C#?

S

SHUBHAMSINGH10
Improve
Article Tags :
  • C#
  • CSharp-string

Similar Reads

  • How to create the StringBuilder in C#
    StringBuilder() constructor is used to initialize a new instance of the StringBuilder class which will be empty and will have the default initial capacity. StringBuilder is used to represent a mutable string of characters. Mutable means the string which can be changed. So String objects are immutabl
    2 min read
  • Different Methods to Read a Character in C#
    In C#, we know that Console.Read() method is used to read a single character from the standard output device. And also there are different methods available to read the single character. Following methods can be used for this purpose: Console.ReadLine()[0] MethodConsole.ReadKey().KeyChar MethodChar.
    3 min read
  • How to Compare Strings in C#?
    A string is a collection of characters and is used to store plain text. Unlike C or C++, a string in C# is not terminated with a null character. The maximum size of a string object depends on the internal architecture of the system. A variable declared followed by "string" is actually an object of s
    13 min read
  • How to remove all characters from StringBuilder in C#
    StringBuilder.Clear Method is used to remove all the characters from the current StringBuilder instance. Syntax: public System.Text.StringBuilder Clear (); It returns an StringBuilder object whose length will be zero. Note: Clear is a convenience method that is equivalent to setting the Length prope
    1 min read
  • How to set ASCII Characters in MaskedTextBox in C#?
    In C#, MaskedTextBox control gives a validation procedure for the user input on the form like date, phone numbers, etc. Or in other words, it is used to provide a mask that differentiates between proper and improper user input. In MaskedTextBox control, you are allowed to insert ASCII or non-ASCII(a
    3 min read
  • How to set the Prompt Character in MaskedTextBox in C#?
    In C#, MaskedTextBox control gives a validation procedure for the user input on the form like date, phone numbers, etc. Or in other words, it is used to provide a mask which differentiates between proper and improper user input. In MaskedTextBox control, you are allowed to set a character that repre
    3 min read
  • C# | Char.ConvertToUtf32(String, Int32) Method
    This method is used to converts the value of a UTF-16 encoded character or surrogate pair at a specified position in a string into a Unicode code point. Syntax: public static int ConvertToUtf32 (string s, int index); Parameters: s: A string that contains a character or surrogate pair. index: The ind
    3 min read
  • C# | How to copy a String into another String
    String.Copy(String) Method is used to create a new instance of String with the same value as a specified String. In other words, this method is used to copy the data of one string into a new string. The new string contains same data like an original string but represents a different object reference
    2 min read
  • C# | Remove all the strings from the StringCollection
    StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.Clear method is used to remove all the strings from the StringCollection. Syntax:
    2 min read
  • C# | How to get TypeCode for the class String
    GetTypeCode() method is used to get the TypeCode of the specified string. Here TypeCode enum represents a specific type of object. In TypeCode every data type is represented by a specific number like String is represented by 18, Int32 is represented by 9, etc. Syntax: public TypeCode GetTypeCode ();
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences