English 中文(简体)
不详。 C#中的盒式/箱式或类型?
原标题:Does int.Parse uses boxing/unboxing or type casting in C#?
  • 时间:2009-10-15 05:52:18
  •  标签:

说什么

 int a = int.Parse("100");

是否有任何箱子/箱子或车内投放的类型?

最佳回答

没有箱子或箱子。 为什么要问? 平价算法比箱/箱式操作成本要高得多,因此,即使有差异,你也会把“纤维”推向业绩差异。

问题回答

我不相信那里有任何 un。 我假定,该守则使用一个瞬变数,并回报,因此没有箱子/箱子。

www.un.org/spanish/ga/president 我只是看着该守则,它非常复杂。 最后价值没有像我想象的那样被打上盒子,但有一些漫长的预处理步骤,因此,即使 box子被打上,也确实不会发生很大变化。

BTW,如果你知道的话,你可以使用Reflector

是的,使用Reflector,你可以确切看到什么进展。 我看不到任何箱子,但有一些 cast子,例如:

private static unsafe void StringToNumber(string str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo info, bool parseDecimal)
{
    if (str == null)
    {
        throw new ArgumentNullException("String");
    }
    fixed (char* str2 = ((char*) str))
    {
        char* chPtr = str2;
        char* chPtr2 = chPtr;
        if (!ParseNumber(ref chPtr2, options, ref number, info, parseDecimal) ||
           ((((long) ((chPtr2 - chPtr) / 2)) < str.Length) && //cast
            !TrailingZeros(str, (int) ((long) ((chPtr2 - chPtr) / 2))))) //cast
        {
            throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
        }
    }
}

或者,这种情况发生于:

private static unsafe char* MatchChars(char* p, string str)
{
    fixed (char* str2 = ((char*) str)) //cast
    {
        char* chPtr = str2;
        return MatchChars(p, chPtr);
    }
}

真正的问题是:

添加我的意思。

The term/technique of "Unboxing" is ONLY relevant for a boxed value type. Thus, if a value type variable is not boxed(converted to reference type), it can be unboxed.

在你看来,你具有有效的参考类型价值,但范围不容置疑。





相关问题
热门标签