Create string in C#

How to define a string in C#.
  • 6155

The string class is used to define strings in C#.

The following code creates three strings with a name, number and double values.

string authorName = "Mahesh Chand";
string age = "33";
string numberString = "33.23"; 

Here is the complete example that shows how to use stings in C# and .NET.

using System;
namespace CSharpStrings
{
    class Program
    {
        static void Main(string[] args)

        {
            // Define C# Strings
            string authorName = "Mahesh Chand";
            string age = "33";
            string numberString = "33.23";  
            // Write to Console.
            Console.WriteLine("Name: {0}", authorName);
            Console.WriteLine("Age: {0}", age);
            Console.WriteLine("Number: {0}", numberString);
            Console.ReadKey();
        }
    }
}

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.