[dba-VB] Getting TextReader from strings...

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Thu Jun 26 02:32:32 CDT 2008


Hi All,

Below is a useful code written two ways:

1) "mere mortals' way" (MMW)
2) "geek way" (geeks will agree hopefully - in fact there exists even
"geekier" version of this code (contest! contest! - for Friday :)) - I used
"moderate geek way"(MGW) mode)

Questions:

1) Which way you prefer? (I personally prefer "mere mortals' way".
2) Anybody who is in love with ILDASM could you please check does the two
version of code generate the same IL in code optimization mode or even
always?

Thank you.

--
Shamil

P.S. Subject code:

//1. MMW

private TextReader Test1()
{
    StringBuilder sb = new StringBuilder();
    sb.AppendLine("Line1");
    sb.AppendLine("Line2");
    sb.AppendLine("Line3");            
    System.Text.ASCIIEncoding ascii = new ASCIIEncoding();
    byte[] bytes = ascii.GetBytes(sb.ToString());
    MemoryStream ms = new MemoryStream(bytes); 
    return new StreamReader(ms);
}

//2. MGW

private TextReader Test2()
{
    StringBuilder sb = new StringBuilder();
    sb.AppendLine("Line1");
    sb.AppendLine("Line2");
    sb.AppendLine("Line3");            
    return 
        new StreamReader( 
        new MemoryStream((
        new ASCIIEncoding(
        )).GetBytes(sb.ToString())));
}





More information about the dba-VB mailing list