… class Example private TimcurrentTime

… class Example private TimcurrentTime插图

, (struct), , . , (class). .

, , , (reference type), (value type). , , , (heap), (stack). :, : ( ), – . , , . : , out ref.

: (, ) , . , , , , . .

, , . ( ), .

, , . C int,long,float ,System.Int64System.Single. . . , ToString. , ,Int32.MaxValueInt32.MinValue. , , .

, ( ).

struct, :

, , . , – 60. – , :

struct Time public Time(int hh, int mm, int ss) hours = hh % 24; minutes = mm % 60; seconds = ss % 60; public int Hours() return hours; … private int hours, minutes, seconds;

, , . , (==) (!=) . , .

, :

, ( ) , . , , , . 0,falsenull . , . , . , – , .

struct Time private int hours, minutes, seconds; … public Time(int hh, int mm) this.hours = hh; this.minutes = mm; // compile-time error: seconds not initialized

: !

. , :

: !

.

?

?

?

?

, ?

?

, . , Time, :

struct Time private int hours, minutes, seconds; … class Example private Time currentTime; public void Method(Time parameter) Time localVariable; …

nullable ? null:

, , . , , , , :

, , .

, C . : . , . , , , .

(stack).

. . –

. , ( ) . , . . .

: , . .

? 7?

[C NET: Class vs Struct ]: Calabonga

, , ( ). , .

[C NET: Class vs Struct ]: TDenis

/, .

, .

?

, :

struct Time public Time(int hh, int mm, int ss) hours = hh % 24; minutes = mm % 60; seconds = ss % 60; public int Hours() return hours; … private int hours, minutes, seconds;

? 14- ? 🙂

[C NET: Class vs Struct ]: sharok

: , , , volatile.

[C NET: Class vs Struct ]: Calabonga

!!! . !!! , !7/11/2011 10:50:00 AM[C NET: Class vs Struct ]:

?

( ) .

. default. ( ).

C, (Eric Lippert) ) .

, , . ( , 🙂 ). NET . 🙂

, .

— (stack).

…. – ? ?)

: , .

? .. . , , . ?

: ? calabonga: , .. 90% . ?

, , . , … -…???

: ,

, , ( ) ( , )

, , ( ) /

, – , . … NET 2.0

, , .

64

new , , .

64

, , ( : … .)? , ?

. , …

, , , (heap), (stack).

! , .

, , , .

, : ( ), – . , , .

: , out ref.

, . . :

, , , , :

? ? , .

. , . , , , .

: – /dev/null, – .

P.S. , .

, : 4.0, C. Calabonga, , . MC++ (C++.NET) . , .

P.S. – . . .

,petalvik, . . . , . .

– ?! ? , .

,

nullable …

: What is nullable? … ( ). , . ( ). :))

, .

– , .

The common language runtime (CLR) always allows the creation of value type instances, and there

is no way to prevent a value type from being instantiated. For this reason, value types dont actually even need to have a constructor defined within them, and the C compiler doesnt emit default

parameterless constructors for value types.

, C ??

, – – !!!

new, , . , , ITVDN , .

All Right Reserved and licenced byCreative Commons BY-NC-SA

When using the site materials, a link to the resource is required! v.5.1.43