OOP, C#
OOP, C#
class App
{
public static void Main()
{
String s = new String('a', 5);
Console.WriteLine(s); // aaaaa
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public String(char c, int count);
*/
namespace Nesne
{
class App
{
public static void Main()
{
string s;
s = new string('a', 5);
Console.WriteLine(s); // aaaaa
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public String(char c, int count);
*/
namespace Nesne
{
class App
{
public static void Main()
{
string s;
s = "Bursa";
Console.WriteLine(s); // Bursa
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public String(char c, int count);
*/
namespace Nesne
{
class App
{
public static void Main()
{
string s;
s = "Bursa";
Console.WriteLine(s.Length); // 5
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public String(char c, int count);
*/
namespace Nesne
{
class App
{
public static void Main()
{
string s;
s = "Bursa";
Console.WriteLine(s[2]); // r
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public String(char c, int count);
*/
namespace Nesne
{
class App
{
public static void Main()
{
string s;
Console.Write("Bir yazı giriniz : ");
s = Console.ReadLine();
// Yazıyı tersten yazar
for(int i = s.Length - 1; i >= 0 ; i--)
Console.Write("{0}", s[i]);
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public String(char c, int count);
*/
namespace Nesne
{
class App
{
public static void Main()
{
string s;
s = "Ankara";
s[1] = 'k'; // Error
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
ToLower
ToUpper
*/
namespace Nesne
{
class App
{
public static void Main()
{
string s, k;
s = "Bursa";
k = s.ToUpper();
Console.WriteLine(k);
k = s.ToLower();
Console.WriteLine(k);
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public string Substring(int startIndex)
public string Substring(int startIndex, int length)
*/
namespace Nesne
{
class App
{
public static void Main()
{
string s, k;
s = "istanbul";
k = s.Substring(2); // "tanbul"
Console.WriteLine(k);
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public string Substring(int startIndex)
public string Substring(int startIndex, int length)
*/
namespace Nesne
{
class App
{
public static void Main()
{
string s, k;
s = "istanbul";
k = s.Substring(2, 3); // "tan"
Console.WriteLine(k);
}
}
}
/////////////////////////
////////////////////////////
using System.Net.Http.Headers;
/*
String Sınıfı
public string Substring(int startIndex)
public string Substring(int startIndex, int length)
*/
namespace Nesne
{
class App
{
public static void Main()
{
string date;
string day, month, year;
// gg-aa-yyyy
day = date.Substring(0, 2);
month = date.Substring(3, 2);
year = date.Substring(6, 4);
class App
{
public static void Main()
{
string s;
int index;
if (index == -1)
Console.WriteLine("Cannot find!!!");
else
Console.WriteLine("Found at the {0} index", index);
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public int IndexOf(char value)
public int IndexOf(string value)
public int IndexOf(char value, int startIndex)
public int IndexOf(string value, int startIndex)
*/
namespace Nesne
{
class App
{
public static void Main()
{
string text;
int indexBeg, indexEnd;
// Bugün {hava} çok sıcak
class App
{
public static void Main()
{
string text, result;
int beg = 0, end = 0;
// Bugün {hava} çok sıcak
class App
{
public static void Main()
{
string path, fileName;
int index;
// c:\windows\temp\a.dat
// Yol ifadesindeki dosyanın ismi yazdırılacak.
// Yani sadece 'a' yazdırılacak
/*
bursa.uludag.docx
Dosya isminde birden fazla '.' karakteri bulunabilir.
Bu durumda uzantı son '.' karakterinin sağındaki karakterlerden
oluşmaktadır
*/
Console.WriteLine(fileName);
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public string Remove(int startIndex)
public string Remove(int startIndex, int count)
class App
{
public static void Main()
{
string text, s;
text = "Bursa Uludag Universitesi";
//s = text.Remove(5);
//Console.WriteLine(s); // Bursa
s = text.Remove(6, 6);
Console.WriteLine(s); // "Bursa Universitesi"
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
public string Insert(int startIndex, string value)
>>> Bir yazıya başka bir yazıyı insert etmek için kullanılır
*/
namespace Nesne
{
class App
{
public static void Main()
{
string text, s;
text = "isbul";
s = text.Insert(2, "tan");
Console.WriteLine(s); // istanbul
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
Trim
>> yazının başındaki ve sonundaki fazladan boşlukları kaldırır
*/
namespace Nesne
{
class App
{
public static void Main()
{
string text, s;
text = " Uludag universitesi ";
s = text.Trim();
Console.WriteLine(":{0}:", s);
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
Replace
public string Replace(char oldChar, char newChar)
public string Replace(string oldValue, string newValue)
*/
namespace Nesne
{
class App
{
public static void Main()
{
string text, s;
text = "Uludag universitesi";
s = text.Replace('e', 'E');
Console.WriteLine("{0}", s);
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
String Sınıfı
Replace
public string Replace(char oldChar, char newChar)
public string Replace(string oldValue, string newValue)
*/
namespace Nesne
{
class App
{
public static void Main()
{
string text, s;
text = "ali top at, ali ip atla";
s = text.Replace("ali", "veli");
Console.WriteLine("{0}", s);
}
}
}
/////////////////////////
////////////////////////////
*/
namespace Nesne
{
class App
{
public static void Main()
{
int a; // a değerin kendisini tutar
int [] b; // b adres tutar
// Diziler C#'ta sınıfsal biçinde temsil edilir
b = new int[100]; // dizinin uzunuluğu belirtilirken tamsayı türüne
ilişkin olmalıdır
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
DİZİLER
*/
namespace Nesne
{
class App
{
public static void Main()
{
int[] a = new int[100];
for (int i = 0; i < a.Length; i++)
a[i] = i * i;
for (int i = 0;i < a.Length; i++)
Console.Write("{0} ", a[i]);
Console.WriteLine();
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
DİZİLER
*/
namespace Nesne
{
class App
{
public static void Main()
{
int[] a = new int[5] {1, 2, 3, 4 , 5}; // ilk değer verilebilir
int[] b = new int[] { 1, 2, 3, 4, 5 }; // ilk değer verilebilir
int[] c = new int[4] { 1, 2, 5 }; // Error!!!
int[] d;
int n = 3;
d = new int[n] { 1, 2, 3 }; // Error!!!
// ilk değer verildiğinde, uzunluk belirten ifadenin tam sayı olması
gerekir
}
} /////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
DİZİLER
*/
namespace Nesne
{
class App
{
public static void Main()
{
int[] a = new int[] { 8, 12, 52, 17, 56, 9, 125, 13, 162, 84 };
int max = a[0];
*/
namespace Nesne
{
class App
{
public static void Main()
{
int[] a = new int[] { 8, 12, 52, 17, 56, 9, 125, 13, 162, 84 };
int max;
MyArray.Disp(a);
max = MyArray.GetMax(a);
Console.WriteLine("En Büyük : {0}", max);
}
}
class MyArray
{
public static int GetMax(int[] a)
{
int max = a[0];
*/
namespace Nesne
{
class App
{
public static void Main()
{
int[] a = new int[] { 8, 12, 52, 17, 56, 9, 125, 13, 162, 84 };
Sort.Disp(a);
Sort.Bubble(a);
Sort.Disp(a);
}
}
class Sort
{
public static void Bubble(int[] a)
{
for (int i = 0; i < a.Length - 1; i++)
for (int k = 0; k < a.Length - 1; k++)
if (a[k] > a[k + 1])
{
int temp = a[k];
a[k] = a[k + 1];
a[k + 1] = temp;
}
}
public static void Disp(int[] a)
{
for (int i = 0; i < a.Length; i++)
Console.Write("{0} ", a[i]);
Console.WriteLine();
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
DİZİLER
Bir metodun parametre değişkeni dizi türden olabilir
*/
namespace Nesne
{
class App
{
public static void Main()
{
int[] a = new int[] { 8, 12, 52, 17, 56, 9, 125, 13, 162, 84 };
Sort.Disp(a);
//Sort.Bubble(a);
Sort.Selection(a);
Sort.Disp(a);
}
}
class Sort
{
public static void Bubble(int[] a)
{
for (int i = 0; i < a.Length - 1; i++)
for (int k = 0; k < a.Length - 1; k++)
if (a[k] > a[k + 1])
{
int temp = a[k];
a[k] = a[k + 1];
a[k + 1] = temp;
}
}
public static void Selection(int[] a)
{
int min, minIndex;
for (int i = 0; i < a.Length - 1; i++)
{
min = a[i];
minIndex = i;
for (int k = i + 1; k < a.Length; k++)
if (a[k] < min)
{
min = a[k];
minIndex = k;
}
a[minIndex] = a[i];
a[i] = min;
}
}
public static void Disp(int[] a)
{
for (int i = 0; i < a.Length; i++)
Console.Write("{0} ", a[i]);
Console.WriteLine();
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
DİZİLER
Bir metodun parametre değişkeni dizi türden olabilir
*/
namespace Nesne
{
class App
{
public static void Main()
{
int[] a = new int[] { 8, 12, 52, 17, 56, 9, 125, 13, 162, 84 };
MyArray.Disp(a);
Array.Sort(a); // diziyi sıralar
Array.Reverse(a); // Diziyi tersyüz eder
MyArray.Disp(a);
}
}
class MyArray
{
public static void Disp(int[] a)
{
for (int i = 0; i < a.Length; i++)
Console.Write("{0} ", a[i]);
Console.WriteLine();
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
DİZİLER
Bir metodun parametre değişkeni dizi türden olabilir
*/
namespace Nesne
{
class App
{
public static void Main()
{
int[] a = new int[] { 8, 12, 52, 17, 56, 9, 125, 13, 162, 84 };
int index;
MyArray.Disp(a);
index = Array.IndexOf(a, 56);
if (index == -1)
Console.WriteLine("Bulunamadı!");
else
Console.WriteLine("Bulundu: {0}", index);
}
}
class MyArray
{
public static void Disp(int[] a)
{
for (int i = 0; i < a.Length; i++)
Console.Write("{0} ", a[i]);
Console.WriteLine();
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
DİZİLER
Bir metodun geri dönüş değeri dizi türden olabilir
*/
namespace Nesne
{
class App
{
public static void Main()
{
int[] a;
a = Sample.GetRandomNumbers(1, 100, 10);
Sample.Disp(a);
}
}
class Sample
{
public static int[] GetRandomNumbers(int min, int max, int n)
{
Random rand = new Random();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = rand.Next(min, max+ 1);
return a;
}
public static void Disp(int[] a)
{
for (int i = 0; i < a.Length; i++)
Console.Write("{0} ", a[i]);
Console.WriteLine();
}
}
}
/////////////////////////
////////////////////////////
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
/*
DİZİLER
Bir metodun geri dönüş değeri dizi türden olabilir
*/
namespace Nesne
{
class App
{
public static void Main()
{
Lotto lotto = new Lotto();
int[] column;
column = lotto.GetRandomColumn();
Array.Sort(column);
Lotto.Disp(column);
}
}
class Lotto
{
public Random rand;
public Lotto()
{
rand = new Random();
}
public int[] GetRandomColumn()
{
int[] column = new int[6];
int val;
bool repeat;