<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Compiler Error CS0304 變量類型“type”沒有 new() 約束,因此無法創建該類型的實例 如果實現泛型類,并且需要使用 **new** 關鍵字來創建為類型參數 T 提供的任何類型的新實例,則必須在類聲明中將 [new() 約束](https://msdn.microsoft.com/zh-cn/library/51y09td4.aspx)應用于 T,如下面的示例所示。 ``` class C<T> where T : new() ``` **new()** 約束將通過確保為 T 提供的任何具體類型都具有默認值(無參數構造函數)來實施類型安全。如果您在 T 未指定 **new()** 約束時嘗試在類的正文中使用 **new** 運算符創建類型參數 T 的實例,將出現 CS0304。在客戶端,如果代碼嘗試使用沒有默認構造函數的類型實例化泛型類,則該代碼將生成 [Compiler Error CS0310](https://msdn.microsoft.com/zh-cn/library/42h7h44y.aspx)。 下面的示例會生成 CS0304。 ``` // CS0304.cs // Compile with: /target:library. class C<T> { // The following line generates CS0304. T t = new T(); } ``` 該類的方法中也不允許使用 **new** 運算符。 ``` // Compile with: /target:library. class C<T> { public void ExampleMethod() { // The following line generates CS0304. T t = new T(); } } ``` 若要避免該錯誤,請使用 **new()** 約束聲明類,如下面的示例所示。 ``` // Compile with: /target:library. class C<T> where T : new() { T t = new T(); public void ExampleMethod() { T t = new T(); } } ``` ## 請參閱 [C# Compiler Errors](https://msdn.microsoft.com/zh-cn/library/ms228296.aspx)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看