繁体   English   中英

将结构列表从C#转换为C ++

[英]convert a list of structs from c# to 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,谢谢

这是您的代码到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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM