以下是 C# 中 String 类的属性 –
Sr.No 属性 &说明1Chars
获取当前String对象中指定位置的Char对象。
2Length
获取当前 String 对象中的字符数。
示例
让我们看一个示例 –
现场演示
using System;public class Demo { public static void Main() { string str1 = "h8b9"; string str2 = "abcdef"; Console.WriteLine("Is string1 null or empty? = "+string.IsNullOrEmpty(str1)); Console.WriteLine("Is string2 null or empty? = "+string.IsNullOrEmpty(str2)); bool val = str1 != str2; Console.WriteLine("Is str1 equal to str2? = "+val); for (int i = 0; i输出
这将产生以下输出 -
Is string1 null or empty? = FalseIs string2 null or empty? = FalseIs str1 equal to str2? = Trueh is a letter8 is a numberb is a letter9 is a number登录后复制
Example
现在让我们看另一个例子 -
现场演示
using System;public class Demo { public static void Main() { string str1 = "hijklm"; string str2 = String.Empty; Console.WriteLine("Is string1 null or whitespace? = "+String.IsNullOrWhiteSpace(str1)); Console.WriteLine("Is string2 null or whitespace? = "+String.IsNullOrWhiteSpace(str2)); Console.WriteLine("String1 length = "+str1.Length); Console.WriteLine("String2 length = "+str1.Length); Console.WriteLine("String length = "+"demo".Length); }}登录后复制
输出
这将产生以下示例 -
Is string1 null or whitespace? = FalseIs string2 null or whitespace? = TrueString1 length = 6String2 length = 6String length = 4登录后复制
以上就是C# 字符串属性的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2429313.html