, 1:
if (_) ;
if (_)
{1; 2;....}
, 2:
if (_)
1;
else 2;
if (_)
{ 1; 2; }
else
{; ;....}
, ++. , if (). () . , ++: == && ||!.
. :
switch ( )
{
case _:
break;
case _:
break;
...........
default:
break;
}
++ switch . break; . .
static void Main(string[] args)
{
string s1;
s1 = "ABC";
switch (s1)
{
case"ABC":
Console.WriteLine("Variant 1");
break;
case "DEF":
Console.WriteLine("Variant 2");
break;
default:
Console.WriteLine("Unknown ");
break;
}
Console.ReadLine();
}
1.5. /
/ Console: Write( ), WriteLine( ), ReadLine() . : ReadLine string, . Write, WriteLine . , . Write WriteLine , WriteLine , Write .
Convert. , ToInt32 int; ToDouble double; ToString string. Convert : , .
: :
namespace ConsApp
{
class Program
{
static void Main(string[] args)
{
int i;
double x,y,z;
string s;
Console.Write("i="); //
s = Console.ReadLine(); //
i = Convert.ToInt32(s); //
//
Console.Write("x=");
x = Convert.ToDouble(Console.ReadLine());
//,
y = i * x;
|
|
z = 2 * i - x;
Console.WriteLine("y=" + y);
//
Console.WriteLine(Convert.ToString(z));
//
Console.ReadLine();
} } }
WriteLine , . , , +y. . decimal.
namespace Console5
{
class Class1
{
static void Main(string[] args)
{
decimal d1,d2,d3;
string s;
s=Console.ReadLine();
d1=Convert.ToDecimal(s);
d2=4.5m; //m M decimal
d3=d1*d2;
Console.WriteLine("Answer is:{0:###.##}",d3);
Console.ReadLine();
} } }
{0: ###.##}: .
Console.ReadLine(); .
C# :
//
/*
*/
/// XML-
C# XML- XML-. XML-. XML- .
C# . , .
- [] _
_ [,] _
, .. .
:
static void Main(string[] args)
{ int[] arr1; // 1
int[] arr2=new int[66]; // 2
int[] arr3 = {2, 5, 55, -6, 8}; // 3
string s;
int n;
Console.Write("Count of Elements ");
s=Console.ReadLine();
n=Convert.ToInt32(s);
arr1=new int[n];.... // 4
// 1 , // 4, n. // 2 . // 3 , . , int[]a,b,c; , ( ). C# , 1.
C# . . arr1.Length arr1.
:
static void Main(string[] args)
{
int[,] a;
int[,] b ={ { 1, 2, 3 }, { 4, 5, 6 } };
//
int n, m;
a = new int[6, 12]; //
n = b.GetLength(0); //
//
|
|
Console.WriteLine("n=" + n);
m = b.GetLength(1); //
//
Console.WriteLine("n=" + m);
n = a.GetUpperBound(0); //
//
Console.WriteLine("n=" + n);
m = a.GetUpperBound(1); //
//
Console.WriteLine("n=" + m);
m = a.Length; //
Console.ReadLine();....
}
GetLength(1) GetUpperBound(1)!
. : . . , :
int[] mas2={1,2,3,4};
int[]mas1=new int[4];
mas1=mas2 , , , , . , , mas2.CopyTo(mas1, i); mas2 mas1 i; mas1 . mas1 . mas1 mas2 .
, , C# : (, , ) : .
: double [ ] [ ] q;
, . .
C# :
- while,
- do... while,
- for,
- foreach.
.
while(___)
{
//
}
do
{
//
} while(___);
foreach ( ):
foreach ( in _)
{
//
}
break; ( ) for Continue; ( ).
for foreach : . .
static void Main(string[] args)
{
double[,] a;
int n, m, kolpol=0;
Console.Write("Rows? ");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("Columns? ");
m = Convert.ToInt32(Console.ReadLine());
a = new double[n, m];
for(int i=0; i<=a.GetUpperBound(0);i++)
for (int j = 0; j <= a.GetUpperBound(1); j++)
{
Console.Write("a[" + i + "," + j + "]=");
a[i, j] = Convert.ToDouble(Console.ReadLine());
}
for(int i=0; i<a.GetLength(0); i++)
for(int j=0;j<a.GetLength(1);j++)
if(a[i,j]>0) kolpol++;
double[] pol = new double[kolpol];
int k = 0;
if (pol.Length == 0) Console.WriteLine("No positives");
else {
for (int i = 0; i < a.GetLength(0); i++)
for (int j = 0; j < a.GetLength(1); j++)
if (a[i, j] > 0) pol[k++]=a[i,j];
foreach (double x in pol) //
// pol
Console.WriteLine("x=" + x + " f(x)={0:##.####}",
Math.Sqrt(x));
}
Console.ReadLine();
}
|
|
:
- ( ), .
- a.GetLength(0) a.GetUpperBound(0) , .
- foreach (double x in pol) , .
- pol pol.Length .