📄 arrays.cpp
字号:
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include "stdafx.h"
#using <mscorlib.dll>
#include <tchar.h>
using namespace System;
__gc class Pizza {
public:
int inch;
};
// This is the entry point for this application
int _tmain(void)
{
// Arrays of integers
Console::WriteLine("===arrays===");
Int32 intarray[];
intarray = __gc new Int32[15];
intarray[1] = 15;
Console::WriteLine(intarray[1]);
intarray = __gc new Int32[20];
for (int x=0; x<20; x++) {
intarray[x] = x * 2;
}
Console::WriteLine(intarray->Length);
Array::Reverse(intarray);
for (x=0; x<20; x++) {
Console::WriteLine(intarray[x]);
}
Console::WriteLine("Initialized Int32 array");
Int32 intarray2[] = {1,2,3,4};
Int32 intarray3[] = {Int32(1),Int32(2),Int32(3),Int32(4)};
Console::WriteLine(intarray3[0]);
Console::WriteLine(intarray3[1]);
// Arrays of characters
Char chararray[] = __gc new Char[20];
chararray[0] = 'a';
chararray[1] = 'b';
Console::Write(chararray[0]);
Console::WriteLine(chararray[1]);
Char charar2[] = {'S','T'};
Console::WriteLine(charar2);
String *charstr = new String(charar2);
Console::WriteLine(charstr);
// Array of String
String *strarray[] = __gc new String *[10];
strarray[0] = S"Hi";
strarray[1] = S"There";
Console::WriteLine(strarray[0]);
Console::WriteLine(strarray[1]);
String *strar2[] = {S"Hello", S"All", S"People"};
Console::WriteLine(strar2[0]);
Console::WriteLine(strar2[1]);
Console::WriteLine(strar2[2]);
// Array of my own managed class
Pizza *pepperoni[] = __gc new Pizza *[50];
pepperoni[0] = __gc new Pizza;
pepperoni[0]->inch = 16;
// Hold anything...
Object *oneforall[] = __gc new Object *[50];
oneforall[0] = S"Wow!";
oneforall[1] = __gc new Pizza;
try {
__try_cast<Pizza *>(oneforall[1])->inch = 12;
}
catch(System::InvalidCastException*) {
Console::WriteLine("Bummer, I couldn't cast!");
}
// Array of strings, Array of Chars, and Split
Console::WriteLine("===Split Test===");
String *breakup =
"Dear John, How are you? It's good to talk to you.";
Char splitters[] = {',' , '?' , ' ' , '.'};
String *pieces[] = breakup->Split(splitters);
for (int p=0; p<pieces->Length; p++) {
Console::WriteLine(pieces[p]);
}
Console::WriteLine("===End Split Test===");
// Multidimensional Arrays
Int32 flumbaggle[,];
Int32 zoorabah[,,];
flumbaggle = __gc new Int32[10,5];
//Int32 flumbaggle[,] = __gc new Int32[10,5];
flumbaggle[0,4] = 10;
flumbaggle[2,4] = 30;
zoorabah = __gc new Int32[5,6,7];
zoorabah[4,3,2] = 20;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -