for(int i = 1; i <= 10; i++) {
for(int j = 1; j <= 10; j++) {
Console.Write(Convert.ToString(i*j)+ " ");
--------------------------------------------------------
Console.Write("Enter N: ");
int n = Convert.ToInt32(Console.ReadLine());
for(int i = 0; i < n; i++) {
for(int j = 0; j <= i; j++) {
--------------------------------------------------------
Console.Write("Enter N: ");
int n = Convert.ToInt32(Console.ReadLine());
for(int i = 0; i < n; i++) {
for(int j = 0; j < n-i; j++) {
--------------------------------------------------------
Console.Write("Enter N: ");
int n = Convert.ToInt32(Console.ReadLine());
for(int i = 0; i < n; i++) {
for(int k = 0; k < i; k++) {
for(int j = 0; j < n-i; j++) {
--------------------------------------------------------
Console.Write("Enter N: ");
int n = Convert.ToInt32(Console.ReadLine());
for(int i = 0; i < n; i++) {
for(int k = 0; k < n-i-1; k++) {
for(int j = 0; j <= i; j++) {
--------------------------------------------------------
Console.Write("Enter N: ");
int n = Convert.ToInt32(Console.ReadLine());
for(int i = 0; i < n; i++) {
for(int k = 0; k < n-i-1; k++) {
for(int j = 0; j < (2*i)+1; j++) {
--------------------------------------------------------
int number, i, k, count = 1;
Console.Write("Enter number of rows\n");
number = int.Parse(Console.ReadLine());
for (k = 1; k <= number - 1; k++)
for (i = 1; i <= count; i++)
for (i = 1; i <= 2 * (number - k) - 1; i++)
--------------------------------------------------------
int number, i, k, count = 1;
Console.Write("Enter number of rows\n");
number = int.Parse(Console.ReadLine());
for (k = 1; k <= number; k++)
for (i = 1; i <= count; i++)
for (i = 1; i <= 2 * k - 1; i++)
for (k = 1; k <= number - 1; k++)
for (i = 1; i <= count; i++)
for (i = 1; i <= 2 * (number - k) - 1; i++)
Console.Write("Enter X: ");
int x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Y: ");
int y = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Z: ");
int z = Convert.ToInt32(Console.ReadLine());
FindMinMax(x, y, z, out max, out min);
Console.WriteLine("Min = " + min.ToString());
Console.WriteLine("Max = " + max.ToString());
static void FindMinMax(int n1, int n2, int n3, out int max, out int min) {
if (n1 >= n2 && n1 >= n3) {
if (n2 >= n1 && n1 >= n3) {
if (n3 >= n1 && n3 >= n2) {
if (n1 <= n2 && n1 <= n3) {
if (n2 <= n1 && n1 <= n3) {
if (n3 <= n1 && n3 <= n2) {
--------------------------------------------------------
--------------------------------------------------------
جدا کردن نام و نام خانوادگی
string fullname = textBox1.Text;
int x = fullname.IndexOf(" ");
string name = fullname.Substring(0, x);
string family = fullname.Substring(x + 1);
--------------------------------------------------------
string email = txtEmail.Text;
int a = email.IndexOf("@");
int d = email.LastIndexOf(".");
if (a == -1 || d == -1 || a > d) {
MessageBox.Show("error");
--------------------------------------------------------
Compile error (;) and Runtime errors (divided by zero) and Logical errors (+ instead of -)
Exception Handling: dont' forget to return; after each catch.
System.IO.IOException => خطای IO
System.IndexOutOfRangeException => خطای دسترسی به عنصری که در رنج آرایه نیست
System.ArrayTypeMismatchException => مشابه نبودن نوع آرایه با نوع داده
System.NullReferenceException => خطا هنگام اشاره به یک شی از نوع نال
System.DivideByZeroException => تقسیم بر صفر
System.InvalidCastException => خطای تبدیل نوع
System.OutOfMemoryException => کمبود حافظه
System.StackOverflowException => سر ریز شدن پشته
System.FormatException => empty field
System.OverflowException => big int
int is from -2,000,000,000 to +2,000,000,000
اگر حاصل جمع از ۳۲ بیت بیشتر شود باید با متد چک کردن تصحیح کنیم
sum = 2000000000 + 2000000000
--------------------------------------------------------
Polymorphism = Overloading
class_name object_name = new constructor();
--------------------------------------------------------
متد سازنده یا کانستراکتور هر کلاس در سی شارپ هم نام خود کلاس می•باشد.
این متد رو می•توان اُورلود نیز کرد.
--------------------------------------------------------
کلاس محاسبه محیط و مساحت مستطیل و استفاده از آن
public Rectangle(int t, int a) {
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
int myTool = Convert.ToInt32(txtTool.Text);
int myArz = Convert.ToInt32(txtArz.Text);
Rectangle rect = new Rectangle();
int myArea = rect.Area();
int myBorder = rect.Border();
MessageBox.Show("Area: " + myArea.ToString());
MessageBox.Show("Border: " + myBorder.ToString());
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
int myTool = Convert.ToInt32(txtTool.Text);
int myArz = Convert.ToInt32(txtArz.Text);
Rectangle rect2 = new Rectangle(myTool, myArz);
int myArea2 = rect2.Area();
int myBorder2 = rect2.Border();
MessageBox.Show("Area: " + myArea2.ToString());
MessageBox.Show("Border: " + myBorder2.ToString());
--------------------------------------------------------
کلاس محاسبه محیط و مساحت دایره و استفاده از آن
return pi * Radius * Radius;
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
int myRadius = Convert.ToInt32(txtRadius.Text);
double myArea = c.Area();
double myBorder = c.Border();
MessageBox.Show("Area: " + myArea.ToString());
MessageBox.Show("Border: " + myBorder.ToString());
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
int myRadius = Convert.ToInt32(txtRadius.Text);
Circle c2 = new Circle(myRadius);
double myArea2 = c2.Area();
double myBorder2 = c2.Border();
MessageBox.Show("Area: " + myArea2.ToString());
MessageBox.Show("Border: " + myBorder2.ToString());
--------------------------------------------------------
محیط و مساحت دایره ای به شعاع سه را حساب کنید
double myborder = c.Border();
double myarea = c.Area();
MessageBox.Show("Mohit:" + myborder.ToString());
MessageBox.Show("Masahat:" + myarea.ToString());
--------------------------------------------------------
محیط و مساحت دایره ای به شعاع سه را حساب کنید
Circle c = new Circle(3);
double myborder = c.Border();
double myarea = c.Area();
MessageBox.Show("Mohit:" + myborder.ToString());
MessageBox.Show("Masahat:" + myarea.ToString());
--------------------------------------------------------
مساحت دایره ای به شعاع دو و دایره ای به شعاع سه
return pi * Radius * Radius;
Circle c1 = new Circle();
Circle c2 = new Circle();
--------------------------------------------------------
public const double pi = 3.14;
--------------------------------------------------------
متد های استاتیک فقط به متغیرهای استاتیک دسترسی دارند
برای استفاده از متدهای استاتیک نیازی به تعریف شی نیست
public static double Area(int Rad) {
double masahat = Circle.Area(2);
double mohit = c.Border();
--------------------------------------------------------
type[] ArrayName = new type[length];
int[] arr1 = new int[3]{2,7,12};
int val2 = (int)arr2.GetValue(2);
--------------------------------------------------------
String arrays and methods
string scores = "10,16,18,20";
string[] ScoresArr = scores.Split(',');
for(int i = 0; i < ScoresArr.Length; i++) {
int score = Convert.ToInt32(ScoresArr[i]);
double avg = Sum / (double)ScoresArr.Length;
MessageBox.Show("Moadel = " + avg.ToString());
string scores = "10,16,18,20";
string[] ScoresArr = scores.Split(',');
for(int i = 0; i < ScoresArr.Length; i++) {
int score = Convert.ToInt32(ScoresArr[i]);
MessageBox.Show("Max Score = " + Max.ToString());
پیدا کردن پایین•ترین نمره
string scores = "10,16,18,20";
string[] ScoresArr = scores.Split(',');
for(int i = 0; i < ScoresArr.Length; i++) {
int score = Convert.ToInt32(ScoresArr[i]);
MessageBox.Show("Min Score = " + Min.ToString());
ممرتب سازی صعودی نمرات Bubble Sort
string scores = "10,16,18,20";
string[] arr = scores.Split(',');
for (int write = 0; write < arr.Length; write++) {
for(int sort = 0; sort < arr.Length - 1; sort++){
if ( Convert.ToInt32(arr[sort]) > Convert.ToInt32(arr[sort+1]) ) {
temp = Convert.ToInt32(arr[sort+1]);
arr[sort] = temp.ToString();
for (int i = 0; i < arr.Length; i++) {
MessageBox.Show("Bubble Sort = " + S);