views:

106

answers:

1

I have the following c# code

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; }
        }
    }

I want to convert that code into Visual c++ CLR, Thanks

+2  A: 

Here is a direct translation of your code to 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;
}
Nick Guerrera
Thanks Nick, you mention that you obtain this code using Reflector or something like this, but I don't find it can you please tell mw what was.Thanks
roncansan
was it .NET Reflector
roncansan
I wrote the above code by hand. Someone else posted another answer that has since been deleted with "old syntax" managed C++ obtained from Reflector's C++ decompiler. You can get Reflector here: http://www.red-gate.com/products/reflector/.
Nick Guerrera