本文介绍了如何在C#中的动态物体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前工作的JavaScript。

I was working on javascript before.

在JavaScript中,我这样做是为了创建动态对象,分配属性给它。

In javascript, I do this to create dynamic object and assign properties to it.

var house = new object();
house.kitchen = 1;
house.bedroom = 2;
house.livingroom =3;

如何做同样的东西在C#?

How to do the same stuff in C#?

推荐答案

在C#中有一种叫做动态,你可以使用

in C# there is something called dynamic that you could use

dynamic house = new ExpandoObject();
house.Kitchen = 1;
house.Bedroom = 2;
house.Livingroom =3;



但是,如果我是新来未是我将开始C#,动态具有非常具体的用途,一般在更先进的情况。你真正应该看到的是类和对象。 C#是一种静态语言,和动态是那里只是为了给它多一点灵活性。

but if I am new to c# that is not were I would start, dynamic has very specific uses, typically in more advanced situations. What you really should be looking at is Classes and objects. C# is a static language, and dynamic is there just to give it a bit more flexibility.

这篇关于如何在C#中的动态物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 12:12