.


:




:

































 

 

 

 


. string

, .

. . , . true , .

 

public bool SpeedUp(double accValue)

{

double oldValue = CurrentSpeed;

if ((CurrentSpeed + accValue) > MaxCitySpeed)

CurrentSpeed = MaxCitySpeed;

Else

CurrentSpeed = CurrentSpeed + accValue;

if (CurrentSpeed < 0) CurrentSpeed = 0;

return (oldValue!= CurrentSpeed);

}

.

 

public double MakeSumm(double a, double b)

{

return a + b;

}

++, , .

.

. , .

C# . , , . , . , .

 

, # out ref.

, : [in], [out] - [in-out].

[out] [in-out], [out] . .. , , [out] . [out] . [in-out] . , .

# out ref, ( ).

, ( static).

 

public static void SampleMethod(out Car newCar, ref double speed)

{

newCar = new Car();

newCar.CurrentSpeed = speed;

if (speed < Car.MaxCitySpeed / 2) speed += 10;

}

, out ref .

void Main(string[] args)

{

Car car;

double speed = 20;

Car.SampleMethod(out car, ref speed);

Console.WriteLine("Car speed: {0} New speed: {1}", car.CurrentSpeed, speed);

Console.ReadLine();

}

ref , . ref .

, . (, ) - , . C# out. , , , .

ref out , out . . , out . , . , out .

 

: , , : public, protected, private internal.

, .. C++. internal public, , .

dll .

internal . , , .

String

string, . String C# . - - , , .

. string

 

string . .

:

 

public void TestDeclStrings(){ // string world = ""; //string s1 = new string("s1"); // //string s2 = new string(); // string sssss = new string('s',5); char[] yes = "Yes".ToCharArray(); string stryes = new string(yes); string strye = new string(yes,0,2); Console.WriteLine("world = {0}; sssss={1}; stryes={2};"+" strye= {3}", world, sssss, stryes, strye);}

world , sssss, stryes, strye String.

- . , . .

:

  • (=);
  • (==) (!=);
  • (+);
  • ([]).

, . string - , , "". "" . - . , "" , , , "". . , .

, , , , . .

" + " , .

, . char, , .

, :

public void TestOpers(){ // string s1 ="ABC", s2 ="CDE"; string s3 = s1+s2; bool b1 = (s1==s2); char ch1 = s1[0]; char ch2=s2[0]; Console.WriteLine("s1={0}, s2={1}, b1={2}," + "ch1={3}, ch2={4}", s1,s2,b1,ch1,ch2); s2 = s1; b1 = (s1!=s2); ch2 = s2[0]; Console.WriteLine("s1={0}, s2={1}, b1={2}," + "ch1={3}, ch2={4}", s1,s2,b1,ch1,ch2);}

Join Split

Join Split . Split . Join , .

- , , , .. , , - , , . . Split Join .

:

public string[] Split(params char[]);

Split , . string, , , . , .

Join :

public static string Join(string delimiters, string[] items);

, items, delimiters. , delimiters , items, .

. , . . . :

public void TestSplitAndJoin(){ string txt = " , ," + " , !"; Console.WriteLine("txt={0}", txt); Console.WriteLine(" :"); string[] SimpleSentences, Words; // SimpleSentences Words // // , Split SimpleSentences = txt.Split(','); for(int i=0;i< SimpleSentences.Length; i++) Console.WriteLine("SimpleSentences[{0}]= {1}",i, SimpleSentences[i]); string txtjoin = string.Join(",",SimpleSentences); Console.WriteLine("txtjoin={0}", txtjoin); Words = txt.Split(',', ' '); for(int i=0;i< Words.Length; i++) Console.WriteLine("Words[{0}]= {1}",i, Words[i]); txtjoin = string.Join(" ",Words); Console.WriteLine("txtjoin={0}", txtjoin);}

.

String

, C#, , , , .

, , , C#. , string . Replace, Insert , , .

Insert
Remove
Replace
Substring
IndexOf, IndexOfAny, LastIndexOf, LastIndexOfAny
StartsWith, EndsWith true false, ,
PadLeft, PadRight
Trim, TrimStart, TrimEnd Pad. ,
ToCharArray

 

 



<== | ==>
, |
:


: 2017-04-14; !; : 259 |


:

:

,
==> ...

1731 - | 1672 -


© 2015-2024 lektsii.org - -

: 0.017 .