0% found this document useful (0 votes)
76 views4 pages

Using Using Using Using Using Namespace Class Static Void String

The document contains code examples for several C# exercises. Example 1 prompts the user to enter an integer and displays it. Example 2 creates and populates an array, sums the elements, and displays the sum. Example 3 demonstrates working with lists, removing an element by index, and finding the index of an element. Example 4 extracts date/time components from the current date/time. Example 7 demonstrates string methods like length, indexOf, trim, substring, and counting numeric characters.

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)
76 views4 pages

Using Using Using Using Using Namespace Class Static Void String

The document contains code examples for several C# exercises. Example 1 prompts the user to enter an integer and displays it. Example 2 creates and populates an array, sums the elements, and displays the sum. Example 3 demonstrates working with lists, removing an element by index, and finding the index of an element. Example 4 extracts date/time components from the current date/time. Example 7 demonstrates string methods like length, indexOf, trim, substring, and counting numeric characters.

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/ 4

Ex1

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

namespace exercice_n1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("donner l'entier :");
int i = Int32.Parse(Console.ReadLine());
Console.WriteLine("l'entier est : " + i);
Console.ReadLine();
}
}
}

Ex 2

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

namespace exercice_n2
{
class Program
{
static void CreeTableau()
{
int[] t = new int[5];
for (int i = 0; i < t.Length; i++)
{
Console.Write(" t[" + i + "] = ");
t[i] = Int32.Parse(Console.ReadLine());

}
for (int i = 0; i < t.Length; i++)
{
Console.Write(t[i]+ "+");
}
int Som = 0;
for (int i = 0; i < t.Length; i++)
{
Som += t[i];
}
Console.Write("=" +Som);
}

static void Main(string[] args)


{
CreeTableau();
Console.ReadLine();

}
}
}

Ex 3

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

namespace exerciece_n3
{
class Program
{
static void semaine ()
{
List<string> jours = new List<string> { "Lundi", "Mardi", "Mercredi",
"Jeudi", "Vendredi", "Samedi", "Dimanche" };
foreach (string jour in jours)
{
Console.WriteLine(jour);
}
Console.Write("donner la position du jour a supprimer :");
int i;
jours.RemoveAt(i = Int32.Parse(Console.ReadLine()));
foreach (string jour in jours)
{
Console.Write(jour + " ");
}
Console.Write(" indice de jeudi :");
int indice = jours.IndexOf("Jeudi");
Console.WriteLine(indice);
}
static void Main(string[] args)
{
semaine();
Console.ReadLine();
}
}
}

Ex4

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

namespace exercice_n4
{
class Program
{
static void Main(string[] args)
{
string mDate = DateTime.Now.ToString();
string mYear = DateTime.Now.Year.ToString();
string mMonth = DateTime.Now.Month.ToString();
string mDay = DateTime.Now.Day.ToString();
string mHoure = DateTime.Now.Hour.ToString();
string mMinute = DateTime.Now.Minute.ToString();
string mSecond = DateTime.Now.Second.ToString();
string mMillisecond = DateTime.Now.Millisecond.ToString();
string mSdate = DateTime.Now.ToShortDateString();
Console.WriteLine(
"\n complete date: " + mDate +
"\n year: " + mYear +
"\n month: " + mMonth +
"\n day: " + mDay +
"\n houre: " + mHoure +
"\n minute: " + mMinute +
"\n second: " + mSecond +
"\n millisecond: " + mMillisecond +
"\n short date: " + mSdate);
Console.ReadLine();
}
}
}

Ex7

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

namespace exercice_n7
{
class Program
{
static void Main(string[] args)
{
string str= " C# programming 2017 or Csharp programming 2017 ";
int longueurChaine = str.Length;
Console.WriteLine("la longeure du chaine: "+ longueurChaine);
int indexC = str.IndexOf("C");
int indexc = str.LastIndexOf("C");
Console.WriteLine("La position du premiere occ de c est: " + indexC +
"\nLa position du derniere occ de c est: " + indexc);
string chaineNettoyée = str.Trim();
Console.WriteLine(str);
Console.WriteLine(chaineNettoyée);
string sousChaine = str.Substring(1, 3);
Console.WriteLine(sousChaine);
int k = 0;
foreach (var c in str)
{
if (char.IsNumber(c))
{
k++;
}
}
Console.WriteLine("le nombre de chiffres dans la chaine est: "+k);
Console.ReadLine();
}
}
}

You might also like