如何使用C#计算字符串的长度?

阅读 1197 收藏 0 点赞 0 评论 0

在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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号