Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Stringler, Arrayler, Dosyalar. Diziler SINGLE int[] numbers; int[] numbers = new int[5]; int[] numbers = new int[5] {1, 2, 3, 4, 5}; string[] names ="— 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 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 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 ArrayList liste = new ArrayList(); int[] sayilar ={ 3, 4, 6, 23, 5, 13 }; liste.Add(89); liste.Add(19); foreach (int i in liste) Console.Write(i + " "); Console.WriteLine(""); liste.AddRange(sayilar); // dizi ekle liste.Sort(); // sirala foreach (int i in liste) Console.Write(i + " "); Console.WriteLine(""); liste.Insert(1, 15); // birinci eleman olarak 15 ekle foreach (int i in liste) Console.Write(i + " "); Console.WriteLine(""); liste.Remove(3); // 3 sayisini sil foreach (int i in liste) Console.Write(i + " "); Console.WriteLine(""); liste.Clear(); //listeyi temizle

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\ttwo three: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ı) struct CListOfCars { public String Make; public String Model; public int CarYear; 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(); // Resim eklemeye aşağıdaki 2 yolda olur.. 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 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 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 }


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

Similar presentations


Ads by Google