C#的String.Length属性示例
C#String.Length属性
String.Length属性用于获取字符串对象中的字符总数(字符串的长度);它使用此字符串进行调用并返回字符总数。
语法:
public int Length { get; }参数:无。
返回值:int–它返回字符串/字符串长度中的字符总数。
示例
Input:
string str = "nhooo";
function call:
str.Length;
Output:
11C#使用String.Length属性获取字符串长度的示例
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//字符串变量声明
string str = "nhooo";
//打印字串及其长度
Console.WriteLine("str: " + str);
Console.WriteLine("str length: " + str.Length);
//将“”分配给字符串"" to the string
//并打印其长度
str = "";
Console.WriteLine("After assigning \"\" to the str...");
Console.WriteLine("str: " + str);
Console.WriteLine("str length: " + str.Length);
//按ENTER退出
Console.ReadLine();
}
}
}输出结果
str: nhooo str length: 11 After assigning "" to the str... str: str length: 0
参考:String.Length物业
热门推荐
5 祝福语简短古诗词
10 简短霸气的考试祝福语
11 三八简短祝福语给婆婆
12 学生开学季祝福语简短
13 足球队祝福语简短
14 祖国生日祝福语简短英文
15 关于开车的祝福语简短
16 新疆新年祝福语大全简短
17 端午发给客户祝福语简短
18 对生活祝福语简短精辟