Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 13, 2016
0 parents
commit d295d52
Showing
1,113 changed files
with
77,761 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using namespace System; | ||
|
||
// Arrays in Action | ||
void main() | ||
{ | ||
// Single dimension | ||
array<int>^ a = gcnew array<int>(4); | ||
array<String^>^ b = gcnew array<String^>(4); | ||
|
||
for (int i = 0; i < a->Length; i++) | ||
{ | ||
a[i] = i; | ||
} | ||
|
||
for (int i = 0; i < b->Length; i++) | ||
{ | ||
b[i] = a[i].ToString(); | ||
} | ||
|
||
for (int i = 0; i < b->Length; i++) | ||
{ | ||
Console::WriteLine(b[i]); | ||
} | ||
|
||
Console::WriteLine(); | ||
Array::Reverse(b); | ||
for (int i = 0; i < b->Length; i++) | ||
{ | ||
Console::WriteLine(b[i]); | ||
} | ||
|
||
// Multi dimension uniform | ||
array<int,2>^ c = gcnew array<int,2>(4,3); | ||
array<String^,2>^ d = gcnew array<String^,2>(4,3); | ||
|
||
for (int x = 0; x < c->GetLength(0); x++) | ||
{ | ||
for (int y = 0; y < c->GetLength(1); y++) | ||
{ | ||
c[x,y] = (x*10)+y; | ||
} | ||
} | ||
|
||
Console::WriteLine(); | ||
for (int x = 0; x < d->GetLength(0); x++) | ||
{ | ||
for (int y = 0; y < d->GetLength(1); y++) | ||
{ | ||
Console::Write("{0,-5:00}", c[x,y]); | ||
} | ||
Console::WriteLine(); | ||
} | ||
|
||
// Multi dimension jagged | ||
array< array<int>^ >^ e = gcnew array<array<int>^>(4); | ||
|
||
for (int x = 0; x < e->Length; x++) | ||
{ | ||
e[x] = gcnew array<int>(4+(x*2)); // each row 2 bigger | ||
for(int y = 0; y < e[x]->Length; y++) | ||
{ | ||
e[x][y] = (x*10)+y; | ||
} | ||
} | ||
|
||
Console::WriteLine(); | ||
|
||
for (int x = 0; x < e->Length; x++) | ||
{ | ||
for (int y = 0; y < e[x]->Length; y++) | ||
{ | ||
Console::Write("{0,-5:00}", e[x][y]); | ||
} | ||
Console::WriteLine(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using namespace System; | ||
|
||
// Boolean Fundamental Type in Action | ||
void main() | ||
{ | ||
bool a = 18757; // will give a warning but set to true | ||
bool b = 0; // false | ||
bool c = true; // obviously true | ||
bool d = false; // obviously false | ||
|
||
Console::WriteLine( a ); | ||
Console::WriteLine( b ); | ||
Console::WriteLine( c ); | ||
Console::WriteLine( d ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using namespace System; | ||
|
||
// Boolean Literals in Action | ||
void main() | ||
{ | ||
bool isTrue = true; | ||
bool isFalse = false; | ||
|
||
Console::WriteLine ( isTrue ); | ||
Console::WriteLine ( isFalse ); | ||
|
||
// This is kind of neat. Boolean literals are objects too! | ||
Console::WriteLine ( true.ToString () ); | ||
Console::WriteLine ( false.ToString () ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using namespace System; | ||
|
||
// Boxing in Action | ||
value class POINT | ||
{ | ||
public: | ||
int x, y; | ||
POINT(int x, int y) : x(x) , y(y) {} | ||
}; | ||
|
||
void main() | ||
{ | ||
POINT p1(1,2); | ||
Object ^o = p1; | ||
POINT ^p2 = (POINT)o; | ||
|
||
Console::WriteLine("p1 x={0} y={1}\n", p1.x, p1.y); | ||
Console::WriteLine("o x={0} y={1}\n", ((POINT)o).x, ((POINT)o).y); | ||
Console::WriteLine("p2 x={0} y={1}\n", p2->x, p2->y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
cl Arrays.cpp /clr:safe | ||
cl Boolean.cpp /clr:safe | ||
cl BooleanLiteral.cpp /clr:safe | ||
cl Boxing.cpp /clr:safe | ||
cl CharLiteral.cpp /clr:safe | ||
cl Chars.cpp /clr:safe | ||
cl Decimal.cpp /clr:safe | ||
cl Enums.cpp /clr:safe | ||
cl FloatingPoint.cpp /clr:safe | ||
cl Hello.cpp /clr:safe | ||
cl IntegerLiteral.cpp /clr:safe | ||
cl IntegerTypes.cpp /clr:safe | ||
cl MainArgsNew.cpp /clr:safe | ||
cl MainArgsTrad.cpp /clr:pure | ||
cl ReferenceIndirect.cpp /clr:pure | ||
cl StringFun.cpp /clr:safe | ||
cl StringLiteral.cpp /clr:safe | ||
cl ValueClass.cpp /clr:safe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using namespace System; | ||
|
||
// Character Literals in Action | ||
void main() | ||
{ | ||
char a = 'a'; // character 'a' | ||
Char b = L'b'; // Unicode 'b' | ||
|
||
char t = '\t'; // tab escape | ||
Char s = L'\\'; // Unicode backslash escape | ||
|
||
char d = '\45'; // octal escape | ||
Char e = L'\x0045'; // Unicode hexadecimal escape | ||
|
||
Console::WriteLine ( a ); // displays numeric equiv of 'A' | ||
Console::WriteLine ( b ); // displays the letter 'b' | ||
Console::WriteLine ( t ); // displays numeric equiv of tab | ||
Console::WriteLine ( s ); // displays backslash | ||
Console::WriteLine ( d ); // displays decimal equiv of octal 45 | ||
Console::WriteLine ( e ); // displays the letter 'e' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using namespace System; | ||
|
||
// Character Fundamental Type in Action | ||
void main() | ||
{ | ||
Char a = L'A'; // character literal 'A' | ||
Char b = L'\x0041'; // hex notation for hex 41 which happens to be 'A' | ||
|
||
Console::WriteLine ( a ); | ||
Console::WriteLine ( b ); //Even though I put hex 41 in b, the ASCII 'A' | ||
//is printed due to b being a Char | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using namespace System; | ||
|
||
// Decimal Fundamental Type in Action | ||
void main() | ||
{ | ||
Decimal w = System::Convert::ToDecimal("123456789012345678901.2345678"); | ||
Console::WriteLine( w ); | ||
|
||
Decimal x = (Decimal)0.1234567890123456789012345678; // will get truncated | ||
Decimal y = (Decimal)0.0000000000000000789012345678; // works fine | ||
|
||
Console::WriteLine( x ); | ||
Console::WriteLine( y ); | ||
|
||
// Decimal constructor | ||
Decimal z(0xeb1f0ad2, 0xab54a98c, 0, false, 0); // = 12345678901234567890 | ||
Console::WriteLine( z ); | ||
|
||
// Create a 28 significate digit number | ||
Decimal a = (Decimal)123456789012345000000.00000000; | ||
Decimal b = (Decimal)678901.23456780; | ||
Decimal c = -(a + b); | ||
|
||
Console::WriteLine( c ); // display pre broken Decimal | ||
|
||
// Break it up into 4 parts | ||
array<int>^ d = Decimal::GetBits(c); | ||
|
||
// Reassemble using Decimal constructor | ||
Decimal e(d[0], d[1], d[2], // digits | ||
((d[3] & 0x80000000) == 0x80000000), // sign | ||
((d[3] >> 16) & 0xff) ); // decimal location | ||
|
||
Console::WriteLine( d[0] ); // display part 1 | ||
Console::WriteLine( d[1] ); // display part 2 | ||
Console::WriteLine( d[2] ); // display part 3 | ||
Console::WriteLine( d[3].ToString("X") ); // display part 4 | ||
Console::WriteLine( e ); // display reassembled Decimal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using namespace System; | ||
|
||
enum class PrimeColors { Red, Blue, Yellow }; | ||
|
||
// Enum Type in Action | ||
void main() | ||
{ | ||
PrimeColors color; | ||
|
||
color = PrimeColors::Blue; | ||
|
||
switch (color) | ||
{ | ||
case PrimeColors::Red : | ||
Console::WriteLine("Red"); | ||
break; | ||
case PrimeColors::Blue : | ||
Console::WriteLine("Blue"); | ||
break; | ||
case PrimeColors::Yellow : | ||
Console::WriteLine("Yellow"); | ||
break; | ||
} | ||
|
||
Console::WriteLine(color.ToString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using namespace System; | ||
|
||
// Floating-point Fundamental Types in Action | ||
void main() | ||
{ | ||
float w = 123.456f; // standard decimal notation | ||
float x = 7890e3f; // exponent notation | ||
double y = 34525425432525764765.76476476547654; // too big will truncate | ||
double z = 123456789012345e-300; // exponent will be reset | ||
|
||
Console::WriteLine( w ); // Write out Single | ||
Console::WriteLine( x ); // Write out Single with more zeros | ||
Console::WriteLine( y ); // Write out Double truncated | ||
Console::WriteLine( z ); // Write out Double shift back decimal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using namespace System; | ||
|
||
// The Obligatory Hello World! | ||
void main(void) | ||
{ | ||
Console::WriteLine("Hello C++/CLI World"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using namespace System; | ||
|
||
// Integer Literals in Action | ||
void main() | ||
{ | ||
Console::WriteLine ( 010 ); // An Octal 10 is a base-10 8 | ||
Console::WriteLine ( -010 ); // Negative Octal 10 is a base-10 -8 | ||
|
||
Console::WriteLine ( 0x10 ); // A Hex 10 is a base-10 16 | ||
Console::WriteLine ( -0x10 ); // Negative Hex 10 is a base-10 -16 | ||
|
||
// This is kind of neat. Number literals are objects too! | ||
Console::WriteLine ( (1234567890).ToString() ); | ||
Console::WriteLine ( (0xABCDEF).ToString("X") ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using namespace System; | ||
|
||
// Integer Fundamental Types in Action | ||
void main() | ||
{ | ||
char v = 'F'; // Intialize using charater literal | ||
short w(123); // Intializing using Functional Notation | ||
int x = 456789; // Decimal literal assigned | ||
long y = 987654321l; // long integer literal assigned | ||
Int64 z = 0xFEDCBA9876543210; // Hex literal assigned | ||
|
||
Console::WriteLine( v ); // Write out a char | ||
Console::WriteLine( w ); // Write out a short | ||
Console::WriteLine( x ); // Write out a int | ||
Console::WriteLine( y ); // Write out a long | ||
Console::WriteLine( z ); // Write out a Int64 | ||
Console::WriteLine( z.ToString("x") ); // Write out a Int64 in Hex | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using namespace System; | ||
|
||
// Passing parameters to main() new method | ||
int main(array<System::String ^> ^args) | ||
{ | ||
Console::WriteLine(args->Length); | ||
|
||
for each (String^ s in args) | ||
{ | ||
Console::WriteLine(s); | ||
} | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using namespace System; | ||
|
||
// Passing parameters to main() | ||
int main ( int argc, char *argv[] ) | ||
{ | ||
Console::WriteLine ( argc.ToString() ); | ||
for (int i = 0; i < argc; i++) | ||
{ | ||
Console::WriteLine ( gcnew String(argv[i]) ); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using namespace System; | ||
|
||
ref class RefClass | ||
{ | ||
public: | ||
int X; | ||
|
||
RefClass(int x) | ||
{ | ||
X = x; | ||
} | ||
}; | ||
|
||
// Reference and Indirection in Action | ||
void main() | ||
{ | ||
RefClass rc(10); | ||
RefClass ^o; | ||
|
||
o = %rc; // place a reference of rc in the handle o | ||
Console::WriteLine(o->X); // print out object. This should contain 10. | ||
|
||
rc.X = 20; // place 50 at the address y points to | ||
Console::WriteLine(o->X); // print out object. This should contain 20. | ||
|
||
int %i = rc.X; // assign rc.X to a reference | ||
|
||
i = 30; // change value of reference | ||
Console::WriteLine(o->X); // print out object. This should contain 30. | ||
|
||
Console::WriteLine(); | ||
|
||
int ^y = gcnew int(100); // create a handle to an int | ||
Console::WriteLine(y); // print out int. | ||
|
||
*y = 110; // Assign new value to dereferenced int | ||
Console::WriteLine(*y); // print out dereferenced int. | ||
} |
Oops, something went wrong.