扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:谢启东编译 来源:天极开发 2007年11月12日
关键字:
int main() { /*1*/ Vector<int>^ iv1 = gcnew Vector<int>(4); /*2*/ Console::WriteLine("iv1: {0}", iv1); /*3*/ Vector<int>^ iv2 = gcnew Vector<int>(7, 2); Console::WriteLine("iv2: {0}", iv2); iv2[1] = 55; iv2[3] -= 17; iv2[5] *= 3; Console::WriteLine("iv2: {0}", iv2); /*4*/ Vector<String^>^ sv1 = gcnew Vector<String^>(3); Console::WriteLine("sv1: {0}", sv1); /*5*/ Vector<String^>^ sv2 = gcnew Vector<String^>(5, "X"); Console::WriteLine("sv2: {0}", sv2); sv2[1] = "AB"; sv2[3] = String::Concat(sv2[4], "ZZ"); Console::WriteLine("sv2: {0}", sv2); /*6*/ Vector<DateTime>^ dv1 = gcnew Vector<DateTime>(2); Console::WriteLine("dv1: {0}", dv1); /*7*/ Vector<DateTime>^ dv2 = gcnew Vector<DateTime>(3, DateTime::Now); Console::WriteLine("dv2: {0}", dv2); for (int i = 0; i < dv2->Length; ++i) { Thread::Sleep(1100); dv2[i] = DateTime::Now; } Console::WriteLine("dv2: {0}", dv2); /*8*/ Vector<Vector<int>^>^ viv = gcnew Vector<Vector<int>^>(3); Console::WriteLine("viv: {0}", viv); viv[0] = gcnew Vector<int>(2, 1); viv[1] = gcnew Vector<int>(4, 2); viv[2] = gcnew Vector<int>(3, 5); Console::WriteLine("viv: {0}", viv); /*9*/ Vector<int>^ iv3 = gcnew Vector<int>(4,3); Vector<int>^ iv4 = gcnew Vector<int>(4,3); Vector<int>^ iv5 = gcnew Vector<int>(4,2); Vector<int>^ iv6 = gcnew Vector<int>(5,6); Console::WriteLine("iv3->Equals(iv4) is {0}", iv3->Equals(iv4)); Console::WriteLine("iv3->Equals(iv5) is {0}", iv3->Equals(iv5)); Console::WriteLine("iv3->Equals(iv6) is {0}", iv3->Equals(iv6)); } |
iv1: [0:0:0:0] iv2: [2:2:2:2:2:2:2] iv2: [2:55:2:-15:2:6:2] sv1: [::] sv2: [X:X:X:X:X] sv2: [X:AB:X:XZZ:X] dv1: [1/1/0001 12:00:00 AM:1/1/0001 12:00:00 AM] dv2: [4/9/2005 3:30:40 PM:4/9/2005 3:30:40 PM:4/9/2005 3:30:40 PM] dv2: [4/9/2005 3:30:41 PM:4/9/2005 3:30:42 PM:4/9/2005 3:30:43 PM] viv: [::] viv: [[1:1]:[2:2:2:2]:[5:5:5]] iv3->Equals(iv4) is True iv3->Equals(iv5) is False iv3->Equals(iv6) is False |
generic <typename T> where T : ValueType public ref class Vector { ... }; value class C {}; /*1*/ Vector<int>^ iv; /*2*/ Vector<String^>^ sv; //错误 /*3*/ Vector<DateTime>^ dv; /*4*/ Vector<Vector<int>^>^ viv; //错误 /*5*/ Vector<C>^ cv; |
generic <typename T> where T : ValueType public ref class Vector, IComparable { ... }; |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者