1 / 19

C# introduktion.

C# introduktion. using System; Namespace MyFirst { class eks1 { public static void Main() { Console.WriteLine("Hej!"); Console.Write("Skriv dit navn her: "); string navn = Console.ReadLine(); Console.WriteLine("Hej igen - " + navn +

noreen
Download Presentation

C# introduktion.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C# introduktion. using System; Namespace MyFirst { class eks1 { public static void Main() { Console.WriteLine("Hej!"); Console.Write("Skriv dit navn her: "); string navn = Console.ReadLine(); Console.WriteLine("Hej igen - " + navn + ". Jeg er en meget nyttig og arbejdsom medhjælp."); } } }

  2. C# program struktur. De eksisterende systemer der bruges. Navnet på dette system Komponet1(class) Data og kode Komponet2(class) Data og kode Komponet3(class) Data og kode Komponet4(class) Data og kode

  3. Using System; ...... Namespace ...... { classe komponentnavn1 { Data. metoder. } classe komponentnavn2 { Data. metoder. } class startkomponent { static void Main() { kode; } } }

  4. SimpelPlot

  5. SimpelPlot Main vindue Vælge fil Indlæse fil Plotedata Datafil read() Databuffer Plot vindue Replot Print color graf

  6. namespace SimpelPlot { public class Databuf { private float[] data_val; public int antelm = 0; public Databuf(int size) { data_val = new float[size]; } public void putdata(float val) { data_val[antelm]=val; antelm= antelm + 1; } public float getdata(int x) { return data_val[x]; } } }

  7. using System; namespace SimpelPlot { public class start { private int heltal1= 3; public static void Main() { Databuf buffer= new Databuf(10); buffer.putdata(3.4); buffer.putdata(4.4); float a; a= (float)Math.Sqrt(3.4*4/5); buffer.putdata(a); a= buffer.getdata(0); } } }

  8. Typer

  9. Kontrolstrukturer if (x < y) { min = x; max = y; } else { min = y; max = x; } > < >= <= == != || && ! (x<=y) && (y< z)

  10. Kontrolstrukturer int x= 4; switch (x) { case 1: Console.WriteLine("x=1"); break; case 2: case 3: Console.WriteLine("x= 2 eller 3"); break; default: Console.WriteLine("x er ikke lig 1,2 eller 3"); break; }

  11. Kontrolstrukturer: Loop double[] databuf = new double[5]; for (int i = 0; i < 5; i++) { databuf[i] = 0.0; } int i=0; while (i<5) { databuf[i] = 0.0; i=i+1; }

  12. Tekst strenge float b = 5; Console.WriteLine("a= {0,5:f2}",b); Console.WriteLine("a= {0,-5:f2}", b); b = .678e2F; string str = string.Format("a= {0,7:f2}", b); String str2 = "her er en tekst"; str = str + " her er en tekst - " + str2; Console.WriteLine(str); a= 5,00 a= 5,00 a= 67,80 her er en tekst – her er en tekst

  13. Skrivning til fil FileStream stream = new FileStream("udfil.txt", FileMode.Create); StreamWriter filoutput = new StreamWriter(stream); float b = 5; filoutput.WriteLine("a= {0,5:f2}", b); filoutput.WriteLine("a= {0,-5:f2}", b); float b = .678e2F; str = string.Format("a= {0,7:f2}", b); str2 = "her er en tekst"; str = str + " her er en tekst - " + str2; filoutput.WriteLine(str); filoutput.Flush(); filoutput.Close(); Filen: udfil.txt a= 5,00 a= 5,00 a= 67,80 her er en tekst – her er en tekst

  14. Binær fil FileStream bstream= new FileStream("udfil.bin", FileMode.Create); BinaryWriter bfil = new BinaryWriter(bstream); BinaryReader bin = new BinaryReader(bstream); bfil.Write((double)b); bfil.Write((double)b + 1); bfil.Write((double)b + 2); bstream.Seek(0, SeekOrigin.Begin); Boolean eof = false; while (!eof) { try { Console.WriteLine("in værdi= {0,7:f2}",bin.ReadDouble()); } catch (EndOfStreamException) { eof = true; } } bfil.Close();

  15. Grafik. Skaf ’’Graphics’’ objektet for det du vil tegne på. Fx: Graphics g= grafBox.CreateGraphics(); Pen pen = new Pen(Color.Black,3); g.DrawLine(pen, 0, 0, 100, 100); 0,0

  16. Grafik. Skal gentegnes når: Vindue flyttes, foran liggende vindue fjernes, osv. Løsning: Re-tegn hver gang der komme et Paint-event. private void plot_but_Click( object sender, EventArgs e) { PlotForm pwin = new PlotForm(); pwin.Show(); pwin.setfilname(filename); pwin.setData(databuf); } private void grafBox_Paint(object sender, PaintEventArgs e) {g = e.Graphics; gpen= new Pen(gcolor,1); Pen axpen = new Pen(Color.Black); graf = new Graf(g, grafBox.Width, grafBox.Height); graf.axis(axpen, (float)0.0, (float)10.0); if (data != null) { for (int i = 0; i <= data.antset; i++) graf.curve(g, gpen, data.antelm, data.data_val[i]); } }

  17. DataFil var1 3,4 5,6 7.6 .0e-3 7.4 4.0 5.0 6.0 5.0 var2 3.1 4.2 5.3 6.4 6.7 8.9 2.3 1.7 6.8

  18. SimpelPlot Main vindue Vælge fil Indlæse fil Plotedata Datafil read() Databuffer Plot vindue Replot Print color graf

  19. Klasser Filclass --------------- --------------- Public Filclass(); Public void read(); MainForm --------------- Public Databuf databuf; --------------- Private void fil_but_Click(); Private void in_but_Click(); Private void plot_but_Click(); Databuf --------------- Public float[][] data_val; Public int antset; Public int antem; --------------- Public Databuf(int,int); Public void putdata(int,int,float); Public float getdata(int,int); PlotForm --------------- Private Graf graf; --------------- Public PlotForm(); Public void setData(Databuf); Private void replot_Click(); Private void print_Click(); Private void color_Click(); Graf --------------- --------------- Public void axis(); Public void curve();

More Related