小编Ava*_*lle的帖子

静态参数的初始化顺序

几周前,我从Java切换到C#.今天,我有一个奇怪的行为,我尝试在这个简单的样本中重现它.我正在使用.net FW 4.

我有三个类:第一个是抽象的:

namespace ReadonlyStaticOrder
{
    using System;
    using System.Collections.Generic;

    public abstract class AbstractClass
    {
        public AbstractClass(string value, IEnumerable<string> someValues)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (someValues == null)
            {
                throw new ArgumentNullException("someValues");
            }
            // would do something after...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

第二个 :

namespace ReadonlyStaticOrder
{
    using System.Collections.Generic;

    public sealed class ReadonlyOrderInitialization : AbstractClass
    {
        // this line introduces the bug, since it call the ctor before SomeValues already initialized
        // if removed, …
Run Code Online (Sandbox Code Playgroud)

.net c# compiler-construction initialization

2
推荐指数
1
解决办法
815
查看次数

标签 统计

.net ×1

c# ×1

compiler-construction ×1

initialization ×1