列表框多选不同描述错误

listboxes multiple choices different descriptions error

我创建了一个列表框,其中应该有多个选择,通过选择其中一个选项,将在中显示所选选项的描述label,这区分了选择与选择

我想出了这个代码:

       public Form1()
        {
            InitializeComponent();

            listBox1.DataSource = choices;              
            listBox1.DisplayMember = "name"; 
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            label1.Text = valikud.ElementAt(listBox1.SelectedIndex).description;
        }

        List<dynamic> choices = new List<dynamic>()
        {
            new {

                name = "Choice 1",
                description = "Description 1"
            },
            new {
                name = "Choice 2",
                description = "Description 2"
            }
        };
    }
}

这适用于常规形式,当我将其添加到我的其他程序到 user control 时出现问题,问题出现在:

List<*dynamic*> choices = new List<dynamic>()

错误状态:

错误 CS1980 无法定义 class 或使用 'dynamic' 的成员,因为无法找到编译器所需的类型 'System.Runtime.CompilerServices.DynamicAttribute'。您缺少参考资料吗?

UPDATE: 问题是我的.net framework 版本过时了,我更新到 4.6 之前是 3.0

但是现在这导致了一个新问题,它位于:

 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            label1.Text = *choices.ElementAt(listBox1.SelectedIndex)*.description;
        }

错误状态:

错误 CS0656 缺少编译器所需的成员 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

我怎么可能解决这个问题? -谢谢

您需要检查出现此错误的项目的框架版本。

.NET Framework 4.0 或更高版本支持动态关键字和类型。

确保您项目的目标框架为 4.0 或更高版本,它应该可以解决您的问题。