Full code:
using System.Net
using System.Threading
namespace SoundBoard
{
class Program
{
WebClient client;
string fileName;
static void Main(string[] args)
{
string url = "";
Thread thread = new Thread(() =>
{
Uri uri = new Uri(url);
fileName = System.IO.Path.GetFileName(uri.AbsolutePath); //error CS0120
client.DownloadFileAsync(uri, Application.StartupPath + "/" + fileName); //error CS0120
});
thread.Start();
}
}
}
as I was following a tutorial, I encounter this error. I declared "client" and "fileName" outside the main method because I was gonna need them later in other methods outside the main method.
I've looked at a couple posts, but atleast with client
I don't seem to figure it out.
I tried moving the declaration of the two variables inside of the main method, though this would not only mean that I couldn't use them outside of main, but also gave me a CS0165 "use of unassigned local variable "client".
static void Main(string[] args)
{
WebClient client;
string fileName;
string url = "";
Thread thread = new Thread(() =>
{
Uri uri = new Uri(url);
fileName = System.IO.Path.GetFileName(uri.AbsolutePath); //solved
client.DownloadFileAsync(uri, Application.StartupPath + "/" + fileName); //error CS0165
});
thread.Start();
}
so, how do I solve this, preferrably keeping client and fileName outside of main?