close

FileStream –> object   OK

FileStream->Stream   OK

FileStream->string      NG

FileStream->StreamReader  NG

   1: private void button1_Click(object sender, EventArgs e)
   2:         {
   3:             using (FileStream fs = new FileStream(@"c:\log.txt",System.IO.FileMode.Create))
   4:             {
   5:                 object obj = fs as object;
   6:                 if (obj != null)
   7:                 {
   8:                     MessageBox.Show("轉換為Object成功!", "提示!");
   9:                 }
  10:                 else
  11:                 {
  12:                     MessageBox.Show("轉換為Object不成功!", "提示!");
  13:                 }
  14:                 Stream strm = obj as Stream;
  15:                 if (strm != null)
  16:                 {
  17:                     MessageBox.Show("轉換為Stream成功!", "提示!");
  18:                 }
  19:                 else
  20:                 {
  21:                     MessageBox.Show("轉換為Stream不成功!", "提示!");
  22:                 }
  23:                 string str = obj as string;
  24:                 if (str != null)
  25:                 {
  26:                     MessageBox.Show("轉換為string成功!", "提示!");
  27:                 }
  28:                 else
  29:                 {
  30:                     MessageBox.Show("轉換為string不成功!", "提示!");
  31:                 }
  32:  
  33:                 StreamReader f = obj as StreamReader;
  34:                 if (str != null)
  35:                 {
  36:                     MessageBox.Show("轉換為StreamReader成功!", "提示!");
  37:                 }
  38:                 else
  39:                 {
  40:                     MessageBox.Show("轉換為StreamReader不成功!", "提示!");
  41:                 }
  42:  
  43:             }

44: }

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()