190 likes | 200 Views
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};
E N D
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"};
Ç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"} };
Ç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}
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.
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
ArrayList Fonksiyonları • Add • Capacity • Clear • Count • IndexOf • Insert • RemoveAt • Reverse • Sort • TrimToSize
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];
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) • ...
Ekleme • string a = "holly"; • string b = "wood"; • string c = a + b;
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); • }
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); • }
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);
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"); • } • }
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(); • } • }
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: • }
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 • }