我全新的C,所以忍受我.我想用一个静态数组做一个类,并从main中访问这个数组.这是我想在C#中做的.
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Class a = new Class();
- Console.WriteLine(a.arr[1]);
- }
- }
- }
- =====================
- namespace ConsoleApplication1
- {
- class Class
- {
- public static string[] s_strHands = new string[]{"one","two","three"};
- }
- }
这是我试过的:
- // justfoolin.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <string>
- #include <iostream>
- using namespace std;
- class Class {
- public:
- static string arr[3] = {"one","three"};
- };
- int _tmain(int argc,_TCHAR* argv[])
- {
- Class x;
- cout << x.arr[2] << endl;
- return 0;
- }
但我得到:
IntelliSense:不允许使用数据成员初始化器