Saturday, February 13, 2021

String In C#

A String is a sequential collection of characters that's used to represent text. A String object is a sequential collection of System.Char objects that represent a string. The value of the String object is the content of the sequential collection of System.Char objects, and that value is immutable (that is, it is read-only). 

The maximum of a String object in memory 2-GB ,or about 1 billion characters.

Instantiate to String Object:

Assigning a string literal to a String variable. This is the most commonly used method for creating a string. The following example uses assignment to create several strings. Note that in C#, because the backslash (\) is an escape character, literal backslashes in a string must be escaped or the entire string must be @-quoted.

class Program

    {
        static void Main(string[] args)
        {
            string myStr = "this is string creation by assignment!";
            Console.WriteLine(myStr);
            string myafilePath = "Location of file c:\\docs\\test-file.doc";
            Console.WriteLine(myafilePath);

            string myafilePath2 = @"Location of file c:\docs\test-file.doc";
            Console.WriteLine(myafilePath2);

            Console.ReadKey();
        }
    }



No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...