×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# - Get the Length of a String

Given a string, we have to find it length using C# program.
Submitted by Nidhi, on October 10, 2020 [Last updated : March 21, 2023]

Here, we read a string from the keyboard and then get the length of the string using the Length property.

C# program to get the length of a string

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# - Get the Length of a 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.

C# Basic Programs »

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.