Documente Academic
Documente Profesional
Documente Cultură
TABLOURI
1. Bucla foreach
1.
Consultați Cursul 07
1
Notițe TABLOURI ACTIVITĂȚI 5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cursul07.ex1
{
class Program
{
static void Main(string[] args)
{
const int N = 9;
int[] note;
// note = new int[]{10,9,9,7,5,10,9,8,5};
note = new int[N]{10,9,9,7,5,10,9,8,5};
int min, max, suma;
float media;
/*
note[0] = 10;
note[1] = 9;
note[2] = 9;
note[3] = 7;
note[4] = 5;
note[5] = 10;
note[6] = 9;
note[7] = 8;
note[8] = 5;
*/
min = max = note[0];
suma = 0;
2
ACTIVITĂȚI 5 TABLOURI Notițe
Console.ReadKey();
}
}
}
Tablouri în scară
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cursul07.ex2
{
class Program
{
static void Main(string[] args)
{
3
Notițe TABLOURI ACTIVITĂȚI 5
Console.ReadKey();
}
}
}
sing System;
using System.Collections.Generic;
4
ACTIVITĂȚI 5 TABLOURI Notițe
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cursul07.ex4
{
class Program
{
static void Main(string[] args)
{
// ex1
string str1="Acesta este un string";
string str2=string.Copy(str1);
string str3 = "Acesta este un alt string";
if (str1 == str2)
Console.WriteLine("str1=str2");
else
Console.WriteLine("str1 !=str2");
if (str1 == str3)
Console.WriteLine("str1=str3");
else
Console.WriteLine("str1 !=str3");
// ex2
string S = "Acesta este un string";
string subsirS = "est";
int j,k;
j = S.IndexOf(subsirS);
k = S.LastIndexOf(subsirS);
Console.WriteLine("Primul index este {0}",j);
Console.WriteLine("Ultimul index este {0}", k);
// ex3
string [ ] myStringArray;
char[ ] charArray = { '-' };
string myString="This-is-my-string";
5
Notițe TABLOURI ACTIVITĂȚI 5
myStringArray=myString.Split(charArray,4);
foreach (string ss in myStringArray)
{
Console.WriteLine(ss);
}
Console.ReadKey();
}
}
}
6
ACTIVITĂȚI 5 TABLOURI Notițe
Bucla foreach
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cursul07.ex3
{
class Program
{
static void Main(string[] args)
{
{
int sum = 0;
int[] n = new int[20];
foreach (int x in n)
{
Console.WriteLine("valoarea este: " + x);
sum += x;
}
7
Notițe TABLOURI ACTIVITĂȚI 5
Ap1
1
…
8
ACTIVITĂȚI 5 TABLOURI Notițe
Print
GetName
PlayMusic
SetUserName
And some examples for bad named methods:
Abc11
9
Notițe TABLOURI ACTIVITĂȚI 5
Yellow___Black
foo
_Bar
It is very important that the method name describes the method’s purpose. All behind
this idea is that when a person that is not familiar with our program reads the method
name, they can easily understand what that method does, without the need to look at
the method’s source code.
10