Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements