zoukankan      html  css  js  c++  java
  • 2009年5月小记(StackTrace, Ticks)

    1、如何用反射得到调用当前方法的方法名称?

    StringBuilder sb = new StringBuilder();
    StackTrace st 
    = new StackTrace();
    foreach (StackFrame sf in st.GetFrames())
    {
        sb.Append(sf.GetMethod().Name);
        sb.Append(
    ",");
    }
    return sb.ToString();

    通常第一个StackFrame就是当前方法:

    MethodInfo method = (MethodInfo)(new StackTrace().GetFrame(0).GetMethod());
    return method.Name;


    return new StackFrame(0).GetMethod().Name;


    2、DateTime.Now.Ticks及long转换

    # long实际上就一个Int64: long lg = new long(); 或 long lg = new Int64();

    # DateTime.Now.Ticks的值为long类型。

    # DateTime.Now.Ticks.ToString("x", CultureInfo.InstalledUICulture) 转换为十六进制表示

    # long.Parse(longstr, NumberStyles.HexNumber) 把十六进制表示转换为long类型

    # new DateTime(DateTime.Now.Ticks) 或 new DateTime(long) 把一个long类型转换为DateTime时间表示

    # new TimeSpan(DateTime.Now.Ticks - ClientStartTime).TotalMilliseconds 计算执行时间差

     3 、HashSet<T>使用


  • 相关阅读:
    望其项背 iOS
    望其项背 iOS
    望其项背 iOS
    望其项背 iOS
    望其项背 iOS
    望其项背 iOS
    望其项背 iOS
    望其项背 iOS
    望其项背 iOS
    望其项背 iOS
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760318.html
Copyright © 2011-2022 走看看