<i id='jvhLi'><tr id='jvhLi'><dt id='jvhLi'><q id='jvhLi'><span id='jvhLi'><b id='jvhLi'><form id='jvhLi'><ins id='jvhLi'></ins><ul id='jvhLi'></ul><sub id='jvhLi'></sub></form><legend id='jvhLi'></legend><bdo id='jvhLi'><pre id='jvhLi'><center id='jvhLi'></center></pre></bdo></b><th id='jvhLi'></th></span></q></dt></tr></i><div id='jvhLi'><tfoot id='jvhLi'></tfoot><dl id='jvhLi'><fieldset id='jvhLi'></fieldset></dl></div>
        <bdo id='jvhLi'></bdo><ul id='jvhLi'></ul>
        <tfoot id='jvhLi'></tfoot>
        <legend id='jvhLi'><style id='jvhLi'><dir id='jvhLi'><q id='jvhLi'></q></dir></style></legend>

      1. <small id='jvhLi'></small><noframes id='jvhLi'>

      2. 你能用“where"吗?在 c# 中需要一个属性?

        Can you use quot;wherequot; to require an attribute in c#?(你能用“where吗?在 c# 中需要一个属性?)

          <bdo id='C8csy'></bdo><ul id='C8csy'></ul>
          <tfoot id='C8csy'></tfoot>

            <i id='C8csy'><tr id='C8csy'><dt id='C8csy'><q id='C8csy'><span id='C8csy'><b id='C8csy'><form id='C8csy'><ins id='C8csy'></ins><ul id='C8csy'></ul><sub id='C8csy'></sub></form><legend id='C8csy'></legend><bdo id='C8csy'><pre id='C8csy'><center id='C8csy'></center></pre></bdo></b><th id='C8csy'></th></span></q></dt></tr></i><div id='C8csy'><tfoot id='C8csy'></tfoot><dl id='C8csy'><fieldset id='C8csy'></fieldset></dl></div>
                <tbody id='C8csy'></tbody>
              <legend id='C8csy'><style id='C8csy'><dir id='C8csy'><q id='C8csy'></q></dir></style></legend>

                • <small id='C8csy'></small><noframes id='C8csy'>

                  本文介绍了你能用“where"吗?在 c# 中需要一个属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想做一个只接受可序列化类的泛型类,可以用 where 约束来完成吗?

                  I want to make a generic class that accepts only serializable classes, can it be done with the where constraint?

                  我正在寻找的概念是这样的:

                  The concept I'm looking for is this:

                  public class MyClass<T> where T : //[is serializable/has the serializable attribute]
                  

                  推荐答案

                  不,恐怕不是.您可以对约束做的唯一事情是:

                  Nope, I'm afraid not. The only things you can do with constraints are:

                  • where T : class - T 必须是引用类型
                  • where T : struct - T 必须是不可为空的值类型
                  • where T : SomeClass - T 必须是 SomeClass 或派生自它
                  • where T : ISomeInterface - T 必须是 ISomeInterface 或实现它
                  • where T : new() - T 必须有一个公共的无参数构造函数
                  • where T : class - T must be a reference type
                  • where T : struct - T must be a non-nullable value type
                  • where T : SomeClass - T must be SomeClass or derive from it
                  • where T : ISomeInterface - T must be ISomeInterface or implement it
                  • where T : new() - T must have a public parameterless constructor

                  各种组合都是可行的,但不是全部.与属性无关.

                  Various combinations are feasible, but not all. Nothing about attributes.

                  这篇关于你能用“where"吗?在 c# 中需要一个属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                  Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)

                  <i id='aFW1k'><tr id='aFW1k'><dt id='aFW1k'><q id='aFW1k'><span id='aFW1k'><b id='aFW1k'><form id='aFW1k'><ins id='aFW1k'></ins><ul id='aFW1k'></ul><sub id='aFW1k'></sub></form><legend id='aFW1k'></legend><bdo id='aFW1k'><pre id='aFW1k'><center id='aFW1k'></center></pre></bdo></b><th id='aFW1k'></th></span></q></dt></tr></i><div id='aFW1k'><tfoot id='aFW1k'></tfoot><dl id='aFW1k'><fieldset id='aFW1k'></fieldset></dl></div>

                  <small id='aFW1k'></small><noframes id='aFW1k'>

                      <bdo id='aFW1k'></bdo><ul id='aFW1k'></ul>
                    • <tfoot id='aFW1k'></tfoot>

                        <tbody id='aFW1k'></tbody>

                      1. <legend id='aFW1k'><style id='aFW1k'><dir id='aFW1k'><q id='aFW1k'></q></dir></style></legend>