encountered a C # error "Non-static field, method, or property requires object reference", initially thought to add ref or out,
The result is not a good try. Baidu easy to find is that this is because the static method of the class, the static methods in the class, member functions can only access static data members or static methods.
static void Main (string[] args)//This uses the keyword static representation to be a static method, if the outside method or function must be a static method or a function in the Main method.
In C # even static void Main (string[] args) to access the variables outside of this method must be static.
These are all in the class, and it's OK to access the other classes.
Such as: Access to other classes in the main function, you do not need to add static
The following code calls an error:"A non-static field, method, or property requires an object reference"
Private FileStream selectfilepieces (FileStream filedata, string tempfilepath, int eachlength) {
。。。。。
}
public static void Postfile (Uri requesturi, NameValueCollection postdata, String fileName,
String Filecontenttype, String filefieldname, Cookiecontainer cookies,
NameValueCollection headers,string TempFilePath)
{
FileStream f=selectfilepieces (Filedata, tempfilepath,eachlength); 。。。。。。
}
Only need to add static
private static FileStream selectfilepieces (FileStream filedata, string tempfilepath, int eachlength) {
。。。。。
}