: C#, ListBox. .
, . :
[] [] ([])
{
;
}
. .
, , :
:
o private
o protected
o public ,
, : , C#, void, .
, . , : , , .
, . . .
, , , , . . - , return . , return , .
, :
public double Calc(double a, double b, double c)
{
if (a > b)
return Math.Sin(a) * Math.Cos(b);
else
{
double k = Math.Tan(a * b);
return k * Math.Exp(c / k);
}
}
C# , . . , : , :
/// <summary>
/// X Y
/// </summary>
private int Pow(int X, int Y)
{
int b = 1;
while (Y!= 0)
if (Y % 2 == 0)
{
Y /= 2;
X *= X;
}
else
{
Y--;
b *= X;
}
return b;
}
/// <summary>
/// X Y
/// </summary>
private double Pow(double X, double Y)
{
if (X!= 0)
return Math.Exp(Y * Math.Log(Math.Abs(X)));
|
|
else if (Y == 0)
return 1;
else
return 0;
}
, Pow , :
Pow(3, 17);
Pow(3.0, 17.0);
C# 4.0 (Visual Studio 2010) , . :
private void GetData(int Number, int Optional = 5)
{
Console.WriteLine("Number: {0}", Number);
Console.WriteLine("Optional: {0}", Optional);
}
:
GetData(10, 20);
GetData(10);
Optional 20, , 5, .. .
, , :
private void GetData(int Optional = 5, int Number)
( ref out), . , :
private void Calc(int Number)
{
Number = 10;
}
, Number, . :
int n = 1;
Calc(n);
Console.WriteLine(n);
1, , Calc, . , , . . .
, ref , :
private void Calc(ref int Number)
{
Number = 10;
}
int n = 1;
Calc(ref n);
Console.WriteLine(n);
10: . , .. , .
, , out. , :
private void Calc(out int Number)
{
Number = 10;
}
int n; // !
Calc(out n);
string
C# string. , (, , ) , :
|
|
string a = "";
string b = "";
:
string c = a + " " + b; // :
string String, . , IndexOf , Substring , :
string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int index = a.IndexOf("OP"); // : 14 ( 0)
string b = a.Substring(3, 5); // : DEFGH
, escape-, :
Escape- | |
\" | |
\\ | |
\n | |
\r | |
\t |
ListBox
ListBox , . Items. Items , . Add, RemoveAt Insert , .
Items , . ToString. . , Items , object, , string:
string a = (string)listBox1.Items[0];
SelectedIndex.