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();
    }



  • 相关阅读:
    Windows下使用nmake编译C/C++的makefile
    poj 1228
    poj 1039
    poj 1410
    poj 3304
    poj 1113
    poj 2074
    uva 1423 LA 4255
    poj 1584
    poj 3277
  • 原文地址:https://www.cnblogs.com/frog2008/p/11608489.html
Copyright © 2011-2022 走看看