linq - c# changing this line so it outputs the string as a variable -


update post origianal post after code --- code update david has been helping me throwing 1 error need

using system; using system.collections.generic; using system.linq; using system.text; using system.collections.specialized; using system.net; using system.io;   namespace consoleapplication1 {     class program     {     static void main(string[] args)     {         string url = "http://localhost/test2.php";         webclient webclient = new webclient();          namevaluecollection formdata = new namevaluecollection();         formdata["var1"] = formdata["var1"] = string.format("machinename: {0}", system.environment.machinename);         formdata["var2"] = ip();           byte[] responsebytes = webclient.uploadvalues(url, "post", formdata);         string responsefromserver = encoding.utf8.getstring(responsebytes);         console.writeline(responsefromserver);         webclient.dispose();         system.threading.thread.sleep(5000);     }     public void ip()     {         string publicip = "";          system.net.webrequest request = system.net.webrequest.create("http://checkip.dyndns.org/");         using (system.net.webresponse response = request.getresponse())         {             using (system.io.streamreader stream = new system.io.streamreader(response.getresponsestream()))             {                 publicip = stream.readtoend();             }         }          //search ip in html         int first = publicip.indexof("address: ") + 9;         int last = publicip.lastindexof("</body>");         publicip = publicip.substring(first, last - first);          console.writeline(publicip);         system.threading.thread.sleep(5000);       } } }  error getting  error   2 - object reference required non-static field, method, or property 'consoleapplication1.program.ip()' trying create function send out put var2 

i have c# script

using system; using system.collections.generic; using system.text;  namespace consoleapplication4 { class program {     static void main(string[] args)     {         console.writeline("machinename: {0}", system.environment.machinename);         system.threading.thread.sleep(5000);     } } } 

how can change outputs string variable "var2" , use in script

using system; using system.collections.generic; using system.linq; using system.text; using system.collections.specialized; using system.net; using system.io;   namespace consoleapplication1 { class program {      static void main(string[] args)     {         string url = "http://localhost/test2.php";         webclient webclient = new webclient();         namevaluecollection formdata = new namevaluecollection();         formdata["var1"] = "this var2 needs ";           byte[] responsebytes = webclient.uploadvalues(url, "post", formdata);         string responsefromserver = encoding.utf8.getstring(responsebytes);         console.writeline(responsefromserver);         webclient.dispose();         system.threading.thread.sleep(5000);     } } } 

so how can add machine name script function , use var2 brilliant

using system; using system.collections.generic; using system.text;  namespace consoleapplication5 { class program {     public static int main(string[] args)     {         string publicip = "";          system.net.webrequest request = system.net.webrequest.create("http://checkip.dyndns.org/");         using (system.net.webresponse response = request.getresponse())         {             using (system.io.streamreader stream = new system.io.streamreader(response.getresponsestream()))             {                 publicip = stream.readtoend();             }         }          //search ip in html         int first = publicip.indexof("address: ") + 9;         int last = publicip.lastindexof("</body>");         publicip = publicip.substring(first, last - first);          console.writeline(publicip);         system.threading.thread.sleep(5000);         return 0;     } } } 

her update david incude script in other script looks

formdata["var1"] = formdata["var1"] = string.format("machinename: {0}", system.environment.machinename); formdata["var2"] = "this script needs  "; 

why need in separate application? if 1 application's output going command-line argument application's input, they're both running on same machine. means, in case, they'd both same value system.environment.machinename.

you can value in application it's needed:

formdata["var1"] = string.format("machinename: {0}", system.environment.machinename); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -