zoukankan      html  css  js  c++  java
  • 类的扩展

    自从博客园账号被盗之后好长时间不写随便了,今天开始继续写写

    类的扩展.
    js版
    <script language="javascript">

    var a = "hello"
    console.log(a);

    String.prototype.HasValue = function () {
    if (this == null || this == undefined || this.length == 0)
    return false;
    else
    return true;
    }

    console.log(a.HasValue());

    </script>

    c#版
    public static class StringExrprp
    {
    /// <summary>
    /// 判定字符串是否有值
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static bool HasValue(this string str)
    {
    if (string.IsNullOrEmpty(str))
    {
    return false;
    }
    return true;
    }
    }

    static void Main(string[] args)
    {
    string str = "test";
    Console.WriteLine(str.HasValue());
    //对比原始使用方法
    Console.WriteLine(string.IsNullOrEmpty(str));
    Console.ReadLine();
    }



  • 相关阅读:
    软件测试课堂练习
    JSP第一次作业
    安卓第六次作业
    安卓第五次作业
    第四次安卓作业
    JSP第四周
    软件测试课堂练习3.4
    Android数据库表
    Android购物菜单
    Android增删改查
  • 原文地址:https://www.cnblogs.com/frog2008/p/11608489.html
Copyright © 2011-2022 走看看