草庐IT

human-interface-guidelines

全部标签

c# - 接口(interface)可以包含变量吗?

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:Whycan'tC#interfacescontainfields?大家好JonSkeethasansweredtoaquestionthatUsingapropertyisbackedbyavariable.但接口(interface)中的属性在C#中是允许的。这是否意味着C#中的接口(interface)可以包含一个变量,以及如何处理属性支持的变量?提前致谢。

接口(interface)上的 c# 属性

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭6年前。Improvethisquestion谁能帮我弄清楚在接口(interface)或抽象类上包含属性是否是最佳实践?我会想象一个接口(interface)应该只有方法签名吗?

接口(interface)上的 c# 属性

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭6年前。Improvethisquestion谁能帮我弄清楚在接口(interface)或抽象类上包含属性是否是最佳实践?我会想象一个接口(interface)应该只有方法签名吗?

c# - 具有泛型参数的接口(interface)与具有泛型方法的接口(interface)

假设我有这样的接口(interface)和具体实现publicinterfaceIMyInterface{TMy();}publicclassMyConcrete:IMyInterface{publicstringMy(){returnstring.Empty;}}所以我为strings创建了MyConcrete实现,我可以为int提供一个更具体的实现.没关系。但是假设我想做同样的事情,但是使用通用方法,所以我有publicinterfaceIMyInterface2{TMy();}publicclassMyConcrete2:IMyInterface2{publicstringMy(

c# - 具有泛型参数的接口(interface)与具有泛型方法的接口(interface)

假设我有这样的接口(interface)和具体实现publicinterfaceIMyInterface{TMy();}publicclassMyConcrete:IMyInterface{publicstringMy(){returnstring.Empty;}}所以我为strings创建了MyConcrete实现,我可以为int提供一个更具体的实现.没关系。但是假设我想做同样的事情,但是使用通用方法,所以我有publicinterfaceIMyInterface2{TMy();}publicclassMyConcrete2:IMyInterface2{publicstringMy(

c# - 在 Visual Studio 2005/2008 中实现接口(interface)时删除 automatic#region/#endregion 标记

当用户使用“ImplementIntefaceX”上下文菜单功能时,插入的代码会被包围#region[interfacename]Members#endregion一对。我总是最终删除它,有没有办法可以永久关闭它?我快速搜索了snippets目录,但不确定这是否是正确的地方。我想我可以修改pp_region.snippet,但我感觉会完全关闭#region/#endregion。我想在我开始做一些让我重新安装VS的事情之前先在这里问一下... 最佳答案 您可以通过工具/选项将其关闭然后,在选项窗口中,选择“文本编辑器”,然后选择您选

c# - 在 Visual Studio 2005/2008 中实现接口(interface)时删除 automatic#region/#endregion 标记

当用户使用“ImplementIntefaceX”上下文菜单功能时,插入的代码会被包围#region[interfacename]Members#endregion一对。我总是最终删除它,有没有办法可以永久关闭它?我快速搜索了snippets目录,但不确定这是否是正确的地方。我想我可以修改pp_region.snippet,但我感觉会完全关闭#region/#endregion。我想在我开始做一些让我重新安装VS的事情之前先在这里问一下... 最佳答案 您可以通过工具/选项将其关闭然后,在选项窗口中,选择“文本编辑器”,然后选择您选

c# - 如何将 List<interface> 转换为 List<concrete>?

我有一个接口(interface)定义为:publicinterfaceMyInterface{objectfoo{get;set;};}和一个实现该接口(interface)的类:publicclassMyClass:MyInterface{objectfoo{get;set;}}然后我创建一个返回ICollection的函数,如下所示:publicICollectionClasses(){Listvalue;Listlist=newList(newMyInterface[]{newMyClass{ID=1},newMyClass{ID=1},newMyClass{ID=1}});v

c# - 如何将 List<interface> 转换为 List<concrete>?

我有一个接口(interface)定义为:publicinterfaceMyInterface{objectfoo{get;set;};}和一个实现该接口(interface)的类:publicclassMyClass:MyInterface{objectfoo{get;set;}}然后我创建一个返回ICollection的函数,如下所示:publicICollectionClasses(){Listvalue;Listlist=newList(newMyInterface[]{newMyClass{ID=1},newMyClass{ID=1},newMyClass{ID=1}});v

c# - 为什么要转换为接口(interface)?

在JesseLiberty的C#编程(第142页)中,他提供了一个将对象转换为接口(interface)的示例。interfaceIStorable{...}publicclassDocument:IStorable{...}...IStorableisDoc=(IStorable)doc;...这样做有什么意义,特别是如果对象的类无论如何都实现了接口(interface)?EDIT1:澄清一下,我感兴趣的是强制转换的原因(如果有的话),不是实现接口(interface)的原因。此外,这本书是他的2001年第一版(基于C#1,因此该示例可能与更高版本的C#不相关)。EDIT2:我在代码