Write a program in C#.Net to find the length of a string.

Answer:

using System;

namespace StringLength
{
    class Program
    {
        static void Main(string[] args)
        {
            // Declare a string variable to store the user input
            string inputString;

            // Prompt the user to enter a string
            Console.WriteLine("Enter a string:");

            // Read the input string from the user
            inputString = Console.ReadLine();

            // Find the length of the string using the Length property
            int length = inputString.Length;

            // Output the length of the string
            Console.WriteLine("The length of the string is: " + length);
            Console.ReadLine();
        }
    }
}
Scroll to Top