A string is an object of type String whose value is text. Internally, the text is stored as a sequential read-only collection of Char objects. you can use strings as array of characters, However, more common practice is to use the string keyword to declare a string variable. string is immutable. immutable means that once we have a tendency to produce string object we tend to cannot modify.

Example:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            string firstName, lastname;

            firstName = "Aditya";

            lastname = "Kumar";

 

            string fullname = firstName + " "+ lastname;

            Console.WriteLine("Full Name: {0}", fullname);

 

            //by using string array

            string[] strarray = { "Hello", "Aditya", "Tutorials", "Point" };

            string list = String.Join(" ", strarray);

            Console.WriteLine("Message: {0}", list);

            Console.ReadLine();

        }

    }

}

Result:

What is string in C#

  • String

    • 1. It’s an immutable

    • 2. Performance wise string is slow because every time it will create new instance


    • Thanks.
    •  

    0 comments


    Leave a comment

    Make sure you enter the (*) required information where indicated. HTML code is not allowed.

    you may also like