如何使用 C# 计算字符串的长度?
在 C# 中使用 String.Length 属性来获取字符串的长度。
str.Length
该属性计算字符串中的单词并显示指定字符串的长度,例如,字符串 Amit 有 4 个字符 −
string str = "Amit";
实例
以下是用 C# 编写的计算字符串长度的程序 −
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();
}
}
}输出
String: Amit String Length: 4
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP