Csharp/C Sharp by API/System.IO/FileMode

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

FileMode.Open

<source lang="csharp"> using System; using System.IO;

class MainClass {

 public static void Main(string[] args) { 
   int i; 
   FileStream fin; 
   FileStream fout; 

   try { 
     fin = new FileStream("inputFile.txt", FileMode.Open); 
   } catch(FileNotFoundException exc) { 
     Console.WriteLine(exc.Message + "\nInput File Not Found"); 
     return; 
   } 

   try { 
     fout = new FileStream("outputFile.txt", FileMode.Create); 
   } catch(IOException exc) { 
     Console.WriteLine(exc.Message + "\nError Opening Output File"); 
     return; 
   } 

   try { 
     do { 
       i = fin.ReadByte(); 
       if(i != -1) 
          fout.WriteByte((byte)i); 
     } while(i != -1); 
   } catch(IOException exc) { 
     Console.WriteLine(exc.Message + "File Error"); 
   } 

   fin.Close(); 
   fout.Close(); 
 } 

}


 </source>


FillMode.Alternate

<source lang="csharp"> using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; class FillModesClassical : Form {

   public static void Main() {
       Application.Run(new FillModesClassical());
   }
   public FillModesClassical() {
       ResizeRedraw = true;
       ClientSize = new Size(2 * ClientSize.Height, ClientSize.Height);
   }
   protected override void OnPaint(PaintEventArgs pea) {
       DoPage(pea.Graphics, ForeColor, ClientSize.Width, ClientSize.Height);
   }
   protected void DoPage(Graphics grfx, Color clr, int cx, int cy) {
       Brush brush = new SolidBrush(clr);
       Point[] apt = new Point[5];
       for (int i = 0; i < apt.Length; i++) {
           double dAngle = (i * 0.8 - 0.5) * Math.PI;
           apt[i] = new Point(
                          (int)(cx * (0.25 + 0.24 * Math.Cos(dAngle))),
                          (int)(cy * (0.50 + 0.48 * Math.Sin(dAngle))));
       }
       grfx.FillPolygon(brush, apt, FillMode.Alternate);
   }

}

 </source>