Reputation: 809
I got this class where I need to send POST requests with System.Net.Webclient
. It's working fine as long that I'm using this syntax:
using (WebClient wb = new WebClient())
{
}
But when I try to define an instance of Webclient in the class, it's not recognizable like this.
namespace ConsoleApplication
{
class connection
{
WebClient client = new WebClient();
client.??
}
}
Why can't I do it this way? It seems odd. This method is working fine in static void main of cause.
Thank you in advance
Upvotes: 0
Views: 145
Reputation: 12705
namespace ConsoleApplication
{
class connection
{
WebClient client = new WebClient();
private void SomeMethod(){ Client.[Apply it here]}
}
}
you need some function OR some place to access it. Directly doing what you are trying in the class is not valid
Upvotes: 1