C#如何使用约束声明泛型属性? [英] C# How to declare a generic property with a constraint?

查看:279
本文介绍了C#如何使用约束声明泛型属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试声明一个通用且具有约束且没有运气的属性。是否有可能?


我需要以下内容:

展开 | 选择 | Wrap | 行号

解决方案


我正在尝试声明一个通用且具有约束且没有运气的属性。是否有可能?


我需要以下内容:

展开 | 选择 | Wrap | 行号


问题是以下不起作用:

展开 | 选择 | Wrap | 行号

然后手动投射它?

如果MyDeckPosition继承自IDeckPosition类,你可以投出它:

展开 | 选择 | Wrap | 行号< /跨度>

I''m trying to declare a property that is a generic and has a constraint and having no luck. Is it possible?

I want something like the following:

Expand|Select|Wrap|Line Numbers

解决方案

I''m trying to declare a property that is a generic and has a constraint and having no luck. Is it possible?

I want something like the following:

Expand|Select|Wrap|Line Numbers


The problem with that is that the following does not work:

Expand|Select|Wrap|Line Numbers


Then cast it manually?
If MyDeckPosition inherits from the IDeckPosition class, you chould be able to cast it:

Expand|Select|Wrap|Line Numbers


这篇关于C#如何使用约束声明泛型属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆