1 / 19

Stringler, Arrayler, Dosyalar

Stringler, Arrayler, Dosyalar. Diziler. SINGLE int [] numbers; int [] numbers = new int [5]; int [] numbers = new int [5] {1, 2, 3, 4, 5}; string[] names = new string[3] {"Matt", "Joanne", "Robert"}; or int [] numbers = new int [] {1, 2, 3, 4, 5};

djulius
Download Presentation

Stringler, Arrayler, Dosyalar

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. Stringler, Arrayler, Dosyalar

  2. Diziler • SINGLE • int[] numbers; • int[] numbers = new int[5]; • int[] numbers = new int[5] {1, 2, 3, 4, 5}; • string[] names = new string[3] {"Matt", "Joanne", "Robert"}; • or • int[] numbers = new int[] {1, 2, 3, 4, 5}; • string[] names = new string[] {"Matt", "Joanne", "Robert"}; • or • int[] numbers = {1, 2, 3, 4, 5}; • string[] names = {"Matt", "Joanne", "Robert"};

  3. ÇOK BOYUTLU DİZİLER

  4. ÇOK BOYUTLU DİZİLER • MULTI • string[,] names; • string[,] names = new string[5,4]; • int[,,] buttons = new int[4,5,3]; • int[,] numbers = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} }; • string[,] siblings = new string[2, 2] { {"Mike","Amy"}, {"Mary","Albert"} }; • or • int[,] numbers = new int[,] { {1, 2}, {3, 4}, {5, 6} }; • string[,] siblings = new string[,] { {"Mike","Amy"}, {"Mary","Albert"} }; • or • int[,] numbers = { {1, 2}, {3, 4}, {5, 6} }; • string[,] siblings = { {"Mike", "Amy"}, {"Mary", "Albert"} };

  5. ÇENTİKLİ ÇOK BOYUTLU DİZİLER

  6. ÇENTİKLİ ÇOK BOYUTLU DİZİLER • JAGGED • byte[][] scores; • byte[][] scores = new byte[5][]; • for (int x = 0; x < scores.Length; x++) • { • scores[x] = new byte[4]; • } • int[][] numbers = new int[2][] { new int[] {2,3,4}, new int[] {5,6,7,8,9} }; • or • int[][] numbers = new int[][] { new int[] {2,3,4}, new int[] {5,6,7,8,9} }; • or • int[][] numbers = { new int[] {2,3,4}, new int[] {5,6,7,8,9} }; • int[][] numbers = new int[][] { new int[] {1, 2}, new int[] {3, 4, 5}

  7. Dizi İşlemleri • Dizi işlemleri, programlarda çok sık kullanılan programlama öğelerindendir. • IndexOf() • LastIndexOf() • Sort() // Array.Sort(dizim); • Reverse() // Array.Reverse(dizim) • Array sınıfı yardımıyla kullanılırlar.

  8. ArrayList • ArrayListliste = new ArrayList(); • int[] sayilar ={ 3, 4, 6, 23, 5, 13 }; • liste.Add(89); • liste.Add(19); • foreach (inti in liste) • Console.Write(i + " "); • Console.WriteLine(""); • liste.AddRange(sayilar); // diziekle • liste.Sort(); // sirala • foreach (inti in liste) • Console.Write(i + " "); • Console.WriteLine(""); • liste.Insert(1, 15); // birincielemanolarak 15 ekle • foreach (inti in liste) • Console.Write(i + " "); • Console.WriteLine(""); • liste.Remove(3); // 3 sayisinisil • foreach (inti in liste) • Console.Write(i + " "); • Console.WriteLine(""); • liste.Clear(); //listeyitemizle

  9. ArrayList Fonksiyonları • Add • Capacity • Clear • Count • IndexOf • Insert • RemoveAt • Reverse • Sort • TrimToSize

  10. String • char[] t = new char[5] { 'h', 'e', 'l', 'l', 'o' }; • string a = new string(t); • string s = "hello"; • int l = s.Length; • char c = s[4];

  11. Karşılaştırma • string a = "bike"; • string b = "bit"; • if (a.CompareTo(b) < 0) • ... • if (a.Equals(b)) • ... • if (a == b) • ... • if (a != b) • ...

  12. Ekleme • string a = "holly"; • string b = "wood"; • string c = a + b;

  13. Parçalarına Ayırma • char[] delimiterChars = { ' ', ',', '.', ':', '\t' }; • string text = "one\ttwothree:four,five six seven"; • System.Console.WriteLine("Original text: '{0}'", text); • string[] words = text.Split(delimiterChars); • System.Console.WriteLine("{0} words in text:", words.Length); • foreach (string s in words) • { • System.Console.WriteLine(s); • }

  14. string s = "there is a cat"; • // Split string on spaces. • // ... This will separate all the words. • string[] words = s.Split(' '); • foreach (string word in words) • { • Console.WriteLine(word); • }

  15. Struct(Yapı) structCListOfCars { public String Make; public String Model; public intCarYear; public int Doors; public String CarPicture; }; public partial class Form1 : Form { CListOfCars[] Car = new CListOfCars[5]; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Car[0].Make = "Honda"; Car[0].Model = "Civic"; Car[0].CarYear = 1998; Car[0].CarPicture = "D:\\ cars\\Civic.jpg"; txtMake.Text = Car[0].Make; txtModel.Text = Car[0].Model; txtYear.Text = Car[0].CarYear.ToString(); // Resimeklemeyeaşağıdaki 2 yoldaolur.. pctCarPicture.Image = Image.FromFile(Car[0].CarPicture);

  16. Dosyaya Yazma • public class FileClass • { • public static void Main() • { • WriteToFile(); • } • static void WriteToFile() • { • StreamWriter SW; • SW=File.CreateText("c:\\MyTextFile.txt"); • SW.WriteLine("God is greatest of them all"); • SW.WriteLine("This is second line"); • SW.Close(); • Console.WriteLine("File Created SucacessFully"); • } • }

  17. Dosyadan Okuma • public class FileClass • { • public static void Main() • { • ReadFromFile("c:\\MyTextFile.txt"); • } • static void ReadFromFile(string filename) • { • StreamReader SR; • string S; • SR=File.OpenText(filename); • S=SR.ReadLine(); • while(S!=null) • { • Console.WriteLine(S); • S=SR.ReadLine(); • } • SR.Close(); • } • }

  18. SD KART OKUMA ARDUINO • #include <SD.h> • File dataFile = SD.open("datalog.txt"); • if (dataFile) { • while (dataFile.available()) { • Serial.write(dataFile.read()); • } • dataFile.close(); • } • else { • // if the file isn't open, pop up an error: • }

  19. SD KART YAZMA ARDUINO • #include <SD.h> • File dataFile = SD.open("test.txt", FILE_WRITE); • if (dataFile) { • dataFile.println("writing data to test file"); • dataFile.close(); • } • else { • // if the file didn't open, do something here • }

More Related