如何使用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
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短