• C#_实用


    1.获取当前浏览器信息HttpContext.Current.Request.Browser

    string browser = HttpContext.Current.Request.Browser.Browser;

    brower的值:InternetExplorer,Firefox,Chrome

    2.字符转码/解码  中文乱码时使用

    HttpUtility.UrlEncode("");
    HttpUtility.HtmlDecode("");

    3.使用单例或静态构造函数。一次赋值,多处调用

    单例: //构造函数私有

    private ETest() { }
    public static ETest et = new ETest();

    静态构造函数:

    static ETest()
    {
      Id = 234;
    }
    public static int Id { get; set; }

    4List集合去重

    1)HashSet<string> hs = new HashSet<string>(ls1); //此时已经去掉重复的数据保存在hashset中 速度较快

    2)ls1.Distinct().ToList();

    5.返回多个值 Tuple

    var t = test();
    var a = t.Item1;
    var b = t.Item2;

    public Tuple<test,int> test()
    {
    test t = new test();
    return Tuple.Create(t, 1);
    }

    6.list

    交集
    var intersectedList = list1.Intersect(list2);

    差集
    var expectedList = list1.Except(list2);

    合集
    var mergedList = list1.Merge(list2);

    删除重复项
    var unionList = list1.Union(list2);

    保留重复项
    var concatList = list1.Concat(list2);

  • 相关阅读:
    Java中的==和equals区别
    2014年06月30日
    20140625&nbsp;20:39
    20140627&nbsp;20:47
    2014年06月30日
    20140628&nbsp;16:07
    hdu 1418 抱歉 (数学)
    hdu 1302 The Snail (模拟)
    hdu 1391Number Steps
    hdu 1395 2^x mod n = 1
  • 原文地址:https://www.cnblogs.com/liuph/p/4468013.html
Copyright © 2020-2023  润新知