Q:

C# program to get the length of the string

belongs to collection: C# Basic Programs | String programs

0

C# program to get the length of the string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to get the length of the string in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to get the length of the string.

using System;

class Demo
{
    static void Main()
    {
        string str = "";

        Console.Write("Enter the string: ");
        str = Console.ReadLine();

        Console.WriteLine("Length of string: " + str.Length);
    }
}

Output:

Enter the string: www.includehelp.com
Length of string: 19
Press any key to continue . . .

Explanation:

Here, we created a Demo class that contains the Main() method. The Main() method is the entry point of the program. Here we read a string, and then find the length of the string using the Length property of String class that will be printed on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | String programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to replace a substring within a specifi... >>
<< C# program to extract only numbers from a specifie...