thx, Pascal 解决方案 这是完全可能的,例如,当静态属性返回 同一类的实例时,用于实现 Singleton设计模式。 br /> - 此致, Dmitriy Lapshin [C#/ .NET MVP] 带来今天对VS .NET IDE进行单元测试的能力! http: //www.x-unity.net/teststudio.aspx " Paschalis Pagonidis" <一个******* @ discussions.microsoft.com>在消息中写道 news:4a **************************** @ phx.gbl ... 我有一个类,它的所有属性,属性和方法都是静态的。 但是,我想要一个方法返回一个应该是非静态的对象。 这可能吗? thx, Pascal Paschalis Pagonidis< an ******* @ discussion.microsoft.com>写道:我有一个类,其所有的属性,属性和方法都是静态的。 然而,我想要一个方法来返回一个应该 这可能吗? 对象本身不是静态的或非静态的 - 概念只是 不适用。你能详细介绍一下你想要做什么吗? - Jon Skeet - < sk***@pobox.com> http://www.pobox。 com / ~siget 如果回复小组,请不要给我发邮件 嗨Dmitriy, 你能给我一个例子吗? 例如: 公共类MyClass { 公共静态对象CreateObject() { //我希望obj是非静态的 对象obj = new object(); 返回obj; } 谢谢, Pascal -----原始消息----- 那是完全可能的,是例如,当静态属性返回同一类的实例时,用于实现的单独设计模式。 - 真诚,Dmitriy Lapshin [C#/ .NET MVP] 今天将单元测试的强大功能带到VS .NET IDE中! http://www.x-unity.net/teststudio.aspx Paschalis Pagonidis < an ******* @ discussion.microsoft.com>在messagenews中写道:4a **************************** @ phx.gbl ... 我有一个类,它的所有属性,属性和方法都是静态的。 但是,我想要一个方法来返回一个应该是非静态的。 这可能吗? thx, Pascal 。 Hi,I have a class which all its attributes, properties andmethods are static.However, I want a method to return an object that shouldbe non-static.Is that possible?thx,Pascal 解决方案 Hi,That''s perfectly possible and is, for example, used in implementation of theSingleton design pattern when a static property returns an instance of thesame class.--Sincerely,Dmitriy Lapshin [C# / .NET MVP]Bring the power of unit testing to the VS .NET IDE today! http://www.x-unity.net/teststudio.aspx"Paschalis Pagonidis" <an*******@discussions.microsoft.com> wrote in messagenews:4a****************************@phx.gbl... Hi, I have a class which all its attributes, properties and methods are static. However, I want a method to return an object that should be non-static. Is that possible? thx, Pascal Paschalis Pagonidis <an*******@discussions.microsoft.com> wrote: I have a class which all its attributes, properties and methods are static. However, I want a method to return an object that should be non-static. Is that possible?Objects themselves aren''t static or non-static - the concept justdoesn''t apply. Could you give more details about what you''re trying todo?--Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeetIf replying to the group, please do not mail me tooHi Dmitriy,can you give me an example?for example:public class MyClass{public static object CreateObject(){// I want obj to be non-staticobject obj = new object();return obj;}thanks,Pascal -----Original Message-----Hi,That''s perfectly possible and is, for example, used inimplementation of theSingleton design pattern when a static property returnsan instance of thesame class.--Sincerely,Dmitriy Lapshin [C# / .NET MVP]Bring the power of unit testing to the VS .NET IDE today!http://www.x-unity.net/teststudio.aspx"Paschalis Pagonidis"<an*******@discussions.microsoft.com> wrote in messagenews:4a****************************@phx.gbl... Hi, I have a class which all its attributes, properties and methods are static. However, I want a method to return an object that should be non-static. Is that possible? thx, Pascal. 这篇关于静态类方法返回非静态对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 21:12
查看更多