0% found this document useful (0 votes)
93 views

Program: Using Using Using Using Using Namespace Class Static Void Int Try For Int

The document contains code examples in C# for several concepts: 1. Defining a method to display the contents of an integer array and handle index out of bounds exceptions. 2. Prompting the user for input and parsing it to an integer. 3. Defining a list of strings for weekdays and demonstrating adding/removing elements and searching by index. 4. Defining classes for squares and cubes where cubes inherit from squares and override the surface area method. 5. Defining a Point class with private properties for x and y coordinates, a static property to count instances, and methods for distance between two points.

Uploaded by

marwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

Program: Using Using Using Using Using Namespace Class Static Void Int Try For Int

The document contains code examples in C# for several concepts: 1. Defining a method to display the contents of an integer array and handle index out of bounds exceptions. 2. Prompting the user for input and parsing it to an integer. 3. Defining a list of strings for weekdays and demonstrating adding/removing elements and searching by index. 4. Defining classes for squares and cubes where cubes inherit from squares and override the surface area method. 5. Defining a Point class with private properties for x and y coordinates, a static property to count instances, and methods for distance between two points.

Uploaded by

marwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AfficheByIndexOf
{
class Program
{
static void AfficheTab(int[] t)
{
try
{
for(int i=0;i<t.Length/*+2 pour declencher l'exception*/;i++)
Console.WriteLine("t[" + i + "]=" + t[i]);
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("erreur, index pris en dehors des bornes du tableau");
}
}
static void Main(string[] args)
{
int[] t = { 4, 78, 7, 11, 2, 3, 6, 9, 87, 4, 1, 5, 24, 569, 64, 74 };
AfficheTab(t);
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace afficheEntier
{
class Program
{
static void Main(string[] args)
{
Console.Write("donner i:");
Console.WriteLine("i=" + Int32.Parse(Console.ReadLine()));
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace listWeek
{
class Program
{
static void Main(string[] args)
{
List<string> jours = new List<string> { "Lundi", "Mardi", "Mercredi", "Jeudi",
"Vendredi", "Samedi", "Dimanche" };
Console.WriteLine("affichage list:");
foreach (string j in jours)
{
Console.WriteLine(j);
}
jours.RemoveAt(1);
Console.WriteLine("affichage list apres suppression de l'element d'indice
1:");
foreach (string j in jours)
{
Console.WriteLine(j);
}

Console.WriteLine("la position de \"Jeudi\" est:" + jours.IndexOf("Jeudi"));


}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Carre
{
class Carre
{
int Long;

public Carre(int l)
{
Long = l;
}

public long Surface()


{
return Long * Long;

}
}

class Cube: Carre


{
public Cube(int l) :base(l)
{

public long Surface()


{
return (6 * base.Surface());
}
}
class Program
{
static void Main(string[] args)
{
Carre c = new Carre(4);
Cube cu = new Cube(2);

Console.WriteLine("surface du carre est:" + c.Surface());


Console.WriteLine("surface du cube est:" + cu.Surface());
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Point
{
class Point
{
private double x;
private double y;
private static int numPoints;
private double X
{
get
{
return x;
}

set
{
x = value;
}
}
private double Y
{
get
{
return y;
}

set
{
y = value;
}
}

static Point()
{
numPoints = 0;
}
public Point(double xx, double yy)
{

X = xx;
Y = yy;
Console.WriteLine("x=" + X + " et y=" + Y);
numPoints++;
}

public static void NbInstanceActive()


{
Console.WriteLine( numPoints+ " point(s) actif(s)");
}

public void DistanceX_Y(ref Point p)


{
double sqrt = (p.X - X) * (p.X - X) + (p.Y - Y) * (p.Y - Y);
sqrt = Math.Sqrt(sqrt);
Console.WriteLine("Distance="+sqrt);
}

}
class Program
{
static void Main(string[] args)
{
Point p1 = new Point(5, 7);
Point.NbInstanceActive();
Point p2 = new Point(2, 5);
Point.NbInstanceActive();
p2.DistanceX_Y(ref p1);

}
}
}

You might also like