-4

在 Ruby 中,我们可以通过以下方式创建类方法:

 def self.class_method
   "This is a class method"
 end

 def instance_method
   "This is an instance method"
 end

如何在 C# 中创建类方法?

4

2 回答 2

2

....static和非static..

public class YourObject {
    public static void MyClassMethod() { // "class method" is a static method
    }

    public void MyInstanceMethod() {
    }
}

// callable as..

YourObject.MyClassMethod();
// or..
YourObject obj = new YourObject();
obj.MyInstanceMethod(); // OK

任何教程都涵盖了这个..

于 2013-06-24T03:37:55.433 回答
-1
public class YourClass
{
   public string Foo()
   {
      return "Hello World"
   }

}

YourClass yourClass = new YourClass();
Console.Write(yourClass.Foo());
于 2013-06-24T03:37:10.430 回答