[英]Returning variables from public class C#
I have the following code我有以下代码
public class IDFMeasure
{
,,,,,,,,,,
........
public float [][] GetIDFMeasure(string[] documents)
{
_docs = documents;
_numDocs = documents.Length;
MyInit();
return _termWeight;
}
}
I want to call this class in the main program.我想在主程序中调用这个类。 How I do it ?
我怎么做? I'm getting confused with class types.. Can any help please?
我对课程类型感到困惑..有什么帮助吗? Many thanks
非常感谢
You don't call a class.你不叫一个班级。 You instantiate a class and call its methods.
你实例化一个类并调用它的方法。 You can do so like this:
你可以这样做:
public void main() {
IDFMeasure measure = new IDFMeasure(); // instantiate class
float[][] vals = measure.GetIDFMeasure(documents); // now call method on that class
}
Create object of class and then call the method.创建类的对象,然后调用该方法。
IDFMeasure obj = new IDFMeasure ();
float [][] arr = obj.GetIDFMeasure(new string[]{"1"});
If you only need to call the method and do not need object any more then you can create anonymous object and call method on it.如果您只需要调用方法而不再需要对象,那么您可以创建匿名对象并在其上调用方法。
float [][] arr = new IDFMeasure().GetIDFMeasure(new string[]{"1"});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.