
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to calculate the length of the string using C#?
Use the String.Length property in C# to get the length of the string.
str.Length
The property calculates the words in the string and displays the length of the specified string, for example, the string Amit has 4 characters −
string str = "Amit";
Example
The following is the C# program to calculate the string length −
using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { string str = "Amit"; Console.WriteLine("String: "+str); Console.WriteLine("String Length: "+str.Length); Console.ReadKey(); } } }
Output
String: Amit String Length: 4
- Related Articles
- Python Program to Calculate the Length of a String Without Using a Library Function
- PHP – Get the string length using mb_strlen()
- How to calculate the length of service from hire date in Excel?
- JAVA Program to Calculate Length of Chord of the Circle
- How MySQL LENGTH() function measures the string length?
- How to find the length of the longest substring from the given string without repeating the characters using C#?
- How to get the length of a string in Python?
- How to get the length of a string in JavaScript?
- How to get the Length of a String in Java?
- How to find the length of a string in TypeScript?
- How to calculate the size of folder using Java?
- How to calculate the Size of Folder using C#?
- Write a C program to calculate the average word length of a sentence using while loop
- How to Calculate the Area of a Triangle using Python?
- How to calculate the XOR of array elements using JavaScript?

Advertisements