Copying and Pasting cs Code
In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.
For example, you can follow the pattern in this listing: public void RegisterByEmail(string email, Origin origin)
{
this.registrationCallback = null;
this.AppId = string.Empty;
this.Message = string.Empty;
this.ReturnCode = -1;
string result;
try
{
WebRequest req = HttpWebRequest.Create(this.RegistrationUri(email, (byte)origin));
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
// now read result
StreamReader reader = new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
}
catch (Exception ex)
{
this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
this.Exception = ex;
return;
}
this.ParseResult(result);
}
{
this.registrationCallback = null;
this.AppId = string.Empty;
this.Message = string.Empty;
this.ReturnCode = -1;
string result;
try
{
WebRequest req = HttpWebRequest.Create(this.RegistrationUri(email, (byte)origin));
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
// now read result
StreamReader reader = new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
}
catch (Exception ex)
{
this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
this.Exception = ex;
return;
}
this.ParseResult(result);
}