本文介绍了CS0536的基本原理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我还是C#的新手,所以也许有人可以解释一下我的理由 CS0536:' 'someClass''没有实现接口成员 ''some.Interface.Member()''。 ''someClass.Member()''要么是静态的,要么是公共的b $ b $,或者返回类型错误。 为什么我不能拥有用静态 方法实现接口的类? IIRC,在Java或C ++中,通过类名(someClass :: Member())或通过 对象实例调用静态成员 是可能的。 。 我的动机是我必须使用数学/随机的 分布。因此我基本上有一个 接口分配{ 双倍概率(双x); } 和几个实现它的类。此外,有一些 计算方法返回分布,因此它们给我 分布实例。好吧到目前为止:) 现在有标准的正态分布。你可能还记得你的数学课上的,它并不依赖于任何特定的参数 并且是常用的。所以我想在很多地方打电话给 StdNormalDistribution :: probability()等。 另外,StdNormalDistribution is_a发布可能是 由上述计算方法返回。所以如果StdNormalDistribution可以作为一个实例返回,那将是很好的 很好 在需要时被静态调用。 有一个好的在C#中解决这个问题的方法?是我的oop设计 坏了吗?我是否忽略了按原样这样做的理由? [当然是其他方式 - 让界面静态但 实例非静态无法工作;我甚至不确定静态是否静态在接口中使用 感觉?] 非常感谢, MatthiasHi all,I''m still new to C# so maybe someone can explain me the rationale forCS0536: ''someClass'' does not implement interface member''some.Interface.Member()''. ''someClass.Member()'' is either static, notpublic, or has the wrong return type.Why can''t I have a class implementing the interface with staticmethods? IIRC, in Java or C++ it''s possbile to call a static membereither through the class name (someClass::Member()) or through anobject instance.My motivation is that I have to work with mathematical/stochasticaldistributions. Thus I basically have aninterface Distribution {double probability(double x);}and several classes implementing it. Additionally, there are somecalculation methods that return "Distribution"s, so they give meinstances of Distributions. Allright so far :)Now there''s the standard normal distribution. As you might rememberfrom your math classes, it does not depend on any specific parametersand is commonly used. So I would like to callStdNormalDistribution::probability() and the like in many places.Additionally, StdNormalDistribution is_a Distribution and may bereturned by the calculation methods mentioned above. So it would benice if StdNormalDistribution could be returned as an instance as wellas being called statically when needed.Is there a "nice" way to work around this in C#? Is my oop designbroken? Am I overlooking a good reason for doing it as-is?[Of course the "other way round" - having the interface static but theinstance non-static cannot work; I''m not even sure if "static" makessense in an interface?]Thanks a lot,Matthias推荐答案 如果我理解正确,返回IDistribution和 想要返回一个标准的正态分布返回 StdNormalDistribution.getInstance();"。 其他客户只会打电话即g。 " StdNormalDistribution.getInstance()。probability(。..)"对于他们需要的 计算。 尽管如此,这似乎是一种实现这种行为的麻烦方式。 所以,回到基本问题 - 为什么他们这样做? 它是什么?在通过实例调用静态 成员时会出现歧义的情况? 祝你好运, MatthiasIf I understand you correctly, methods that return "IDistribution"s andwant to return a standard normal distribution would "returnStdNormalDistribution.getInstance();".Other clients would just call e. g."StdNormalDistribution.getInstance().probability(. ..)" for thecalculations they need.Still, this seems to be a cumbersome way to accomplish that behaviour.So, to come back to the basic question - why did they make it the wayit is? Any case where there would be ambiguities when calling staticmembers via instances?Best regards,Matthias 如果我理解正确,返回IDistribution和的方法想要返回标准正态分布将返回 StdNormalDistribution.getInstance();。 其他客户只会调用e。 g。StdNormalDistribution.getInstance()。probability(。..)对于他们需要的计算。 然而,这似乎是一种麻烦的方式来实现这种行为。所以,回到基本问题 - 为什么他们做它的方式是什么?在通过实例调用静态成员时会出现歧义的任何情况吗? 最好的问候, Matthias If I understand you correctly, methods that return "IDistribution"s and want to return a standard normal distribution would "return StdNormalDistribution.getInstance();". Other clients would just call e. g. "StdNormalDistribution.getInstance().probability(. ..)" for the calculations they need. Still, this seems to be a cumbersome way to accomplish that behaviour. So, to come back to the basic question - why did they make it the way it is? Any case where there would be ambiguities when calling static members via instances? Best regards, Matthias 这篇关于CS0536的基本原理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!