草庐IT

internal-class

全部标签

c# - T[].Contains for struct 和 class 表现不同

这是一个后续问题:List.ContainsandT[].ContainsbehavingdifferentlyT[].Contains当T时表现不同是类和结构。假设我有这个结构:publicstructAnimal:IEquatable{publicstringName{get;set;}publicboolEquals(Animalother)//在这里,通用Equals如我所料被正确调用。但是对于类:publicclassAnimal:IEquatable{publicstringName{get;set;}publicboolEquals(Animalother){return

c# - cocos2d-xna : sprite is not drawn if using instance of a class inherited from sprite

我有一个基于Cocos2DXNA和MonoGame的游戏项目。我想在CCSprite类中添加一些自定义逻辑,所以我创建了一个继承自CCSprite的类。我添加了一个虚拟自动属性并尝试使用此类,但出于某种原因,作为我的自定义Sprite类实例创建的Sprite未显示在图层上,而作为CCSprite类实例的Sprite完全没问题。代码如下所示:publicclassSprite:CCSprite{publicstringSomeProp{get;set;}}...line1:varmySprite1=newSprite("texture.png");line2:varmySprite1=n

c# - CA2104 警告 : Is there any way to mark a class as `Immutable` to suppress it?

考虑下面的代码,它触发了CA2104:Donotdeclarereadonlymutablereferencetypes.publicclassTest{//ThisprovokesCA2104:"Donotdeclarereadonlymutablereferencetypes".protectedreadonlyImmutableClassImmutableMember;}publicclassImmutableClass{}有谁知道以一种可以抑制警告CA2104的方式将类标记为不可变的方法吗?我尝试用[ImmutableObject(true)]装饰MutableClass没有成

c# - FileLoadException 在 InitializeComponent 或 x :Class=

我在InitializeComponent方法中遇到文件加载器异常(第一次机会),或者调试器在多个WPF的xaml-root的x:Class属性处中断用户控制。尽管异常会大大降低导航速度,但一切正常。这是异常信息:Couldnotloadfileorassembly'Company.Solution.UserInterface,Version=0.1.5568.25577,Culture=neutral,PublicKeyToken=45069ab0c15881ce'oroneofitsdependencies.Thelocatedassembly'smanifestdefinitio

c# - 为什么具有 "where T : class"约束的 Generic<T> 方法接受接口(interface)

我有这个interface:publicinterfaceITestInterface{intTestInt{get;set;}}和这个通用方法(带有T:class约束):publicvoidTest()whereT:class{//DoSomething}这个电话:Test();一切都编译并运行,同时interface不是class(或者是吗?)。为什么会这样?我第一次看到这个是在我的WCF代理类上:publicpartialclassTestServiceClient:System.ServiceModel.ClientBase,TestNamespace.ITestService

c# - 代码契约(Contract) : Why are some invariants not considered outside the class?

考虑这个不可变类型:publicclassSettings{publicstringPath{get;privateset;}[ContractInvariantMethod]privatevoidObjectInvariants(){Contract.Invariant(Path!=null);}publicSettings(stringpath){Contract.Requires(path!=null);Path=path;}}这里需要注意两点:有一个保证Path属性永远不会为null的契约不变量构造函数检查path参数值以遵守先前的契约不变量此时,Setting实例永远不能有n

c# - Visual Studio express : free class diagram tool

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。关闭8年前。Improvethisquestion我正在使用c#express并希望使用免费工具来设计我的类图。您有什么推荐的免费工具?

c# - 你如何在 C# 中使用 "override"内部类?

我想在内部类中的System.Web.Script.Services.ScriptHandlerFactory和其他.NET内容中自定义一些内容。不幸的是,这是一个内部类。在此类中尝试自定义方法时,我有哪些选择? 最佳答案 您可能会找到thisrecentarticle启发。基本上,它表示您不能覆盖任何标记为internal的内容,并且来源几乎是权威的。您最好的希望是一种扩展方法。 关于c#-你如何在C#中使用"override"内部类?,我们在StackOverflow上找到一个类似的

c# - 在 "Public"类中包含 "Internal"成员是否是一种糟糕的编程习惯?

如果我只保留声明为“内部”的类中的“protected”、“内部”和“私有(private)”成员(字段、方法、属性、事件),会不会更具体和合适?我在各种代码中看到过这种做法(在“内部”类中有“公共(public)”成员)所以只是想知道这是一种不好的做法还是有一些好处或优势。[只关注C#]感谢您的关注。 最佳答案 不一定。如果您想隐式实现一个接口(interface),那么公共(public)成员是完全可以接受的。但一般来说,如果类是内部类,则公共(public)成员没有多大意义。您不会受到伤害,因为您将无法在定义它的模块之外以强类

c# - 通过反射仅获取当前类(class)成员

假设这段代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Reflection;namespaceTestFunctionality{classProgram{staticvoidMain(string[]args){//System.Reflection.Assembly.GetExecutingAssembly().LocationAssemblyassembly=Assembly.LoadF