2009-11-20 50 views
0

我有下面的C#代码转换结构的清单从C#和C++

static void Main(string[] args) 
{ 
      List<Results> votes = new List<Results>(); 
} 
public struct Results 
    { 
     public int Vote1; 
     public int Vote2; 
     public int Vote3; 
     public Candidate precinctCandidate; 
    }; 
    public class Candidate 
    { 
     public Candidate() 
     { 
     } 
     private string name; 
     public string Name 
     { 
      get { return name; } 
      set { name = value; } 
     } 

     private string lastName; 
     public string LastName 
     { 
      get { return lastName; } 
      set { lastName = value; } 
     } 
    } 

我想要的代码转换到Visual C++ CLR,感谢

回答

2

这里是你的代码的直接翻译C++/CLI:

using namespace System; 
using namespace System::Collections::Generic; 

public ref class Candidate 
{ 
public: 
    Candidate() 
    { 
    } 
    property String^ Name 
    { 
     String^ get() { return this->name; } 
     void set(String^ value) { this->name = value; } 
    } 
    property String^ LastName 
    { 
     String^ get() { return this->lastName; } 
     void set(String^ value) { this->lastName = value; } 
    } 
private: 
    String^ name; 
    String^ lastName; 
}; 

public value class Results 
{ 
public: 
    Int32 Vote1; 
    Int32 Vote2; 
    Int32 Vote3; 
    Candidate^ precinctCandidate; 
}; 

int main(array<String^>^ args) 
{ 
    List<Results> votes = gcnew List<Results>(); 
    return 0; 
} 
+0

感谢尼克,你提到你使用Reflector或类似的东西获得这段代码,但是我不觉得它可以请你告诉mw什么是。 谢谢 – roncansan 2009-11-23 13:36:45

+0

是不是.NET反射器 – roncansan 2009-11-23 13:45:10

+0

我用手写了上面的代码。其他人发布了另一个自从被Reflector的C++反编译器获得的“旧语法”托管C++被删除的答案。您可以在这里获得Reflector:http://www.red-gate.com/products/reflector/。 – 2009-12-09 22:32:55