zoukankan      html  css  js  c++  java
  • String.IsNullOrEmpty官方示例

    // This example demonstrates the String.IsNullOrEmpty() method
    using System;
      
    class Sample 
    {
        public static void Main() 
        {
        string s1 = "abcd";
        string s2 = "";
        string s3 = null;
      
        Console.WriteLine("String s1 {0}.", Test(s1));
        Console.WriteLine("String s2 {0}.", Test(s2));
        Console.WriteLine("String s3 {0}.", Test(s3));
        }
      
        public static String Test(string s)
        {
        if (String.IsNullOrEmpty(s) == true) 
            return "is null or empty";
        else
            return String.Format("("{0}") is not null or empty", s);
        }
    }
    /*
    This example produces the following results:
      
    String s1 ("abcd") is not null or empty.
    String s2 is null or empty.
    String s3 is null or empty.
      
    */

    String类提供的这个IsNullOrEmpty方法十分的优雅,英语就是graceful。String的话一般都会有""和null两种情况,如果自己写,用if(s=="" || s==Null)就不太美妙了。

  • 相关阅读:
    JSP 学习笔记1
    XML scriptlet 连接数据库
    JSP 定义行列数表单创建表格
    JSP_01
    JS创建表格完整
    04-基本的mysql语句
    03-MySql安装和基本管理
    02-数据库概述
    01-MySql的前戏
    爬虫系列
  • 原文地址:https://www.cnblogs.com/shuada/p/3384808.html
Copyright © 2011-2022 走看看