I'm working on project that need do call the same method several times, but with different arguments.
Can I use the same variable or do I have to declare another variable?
For example:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(domains["ServiceLogin"]);
req.Method = "GET";
req.Referer = "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0";
req.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
CookieCollection cookies = response.Cookies;
response.Close();
etc..
Do I use the req
variable or declare req2
for example
req = (HttpWebRequest)WebRequest.Create(domains["ServiceLogin"]);
req.Method = "POST";
req.CookieContainer = myCookieContainer;
What's the best way/practice to do this?
Local variables are cheap; there's no compelling benefit to re-using them unnecessarily. Therefore: write your code so that each variable has a clear purpose and that purpose is described by its name. Once each variable's name describes its purpose, it will become more clear whether you need one variable or multiple variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With