I ask to help with this question. I have three boxing text in the form (this is a tboxCarYear form): tboxCarYear , tboxCarModel , tboxCarColor I want to send these three data to the main form at a time (as an object or class). Individually, everything turns out to send.

From # I started learning recently, but in javascrip I can do it like this:

 var ObjCar=new Object(); // создаю новый объект ObjCar.Model="Mercedes"; ObjCar.Color="blue"; ObjCar.Year=2015; 

Next, I send ObjCar and I would get all the necessary data. How to implement this in C #?

  • From your question, I can imagine that this has nothing to do with the Web. But then why is it in javascript tags? - Dmitry
  • Perhaps you can use anonymous types msdn.microsoft.com/ru-ru/library/bb397696.aspx - Praddos
  • @Dmitry, for some reason it seems to me that this is for an online game, like SAMP, MTA, Garry's Mod, where code is used by its programs. \ Added \ Looks like Lua, there the code is strongly on JS help. - CbIPoK2513

1 answer 1

Create a CarInfo class:

 public class CarInfo { public string Model { get; set; } public string Color { get; set; } public int Year { get; set; } } 

Create an instance and submit it to the form:

 var carInfo = new CarInfo() { Model = tboxCarModel.Text, Color = tboxCarColor, Year = Convert.ToInt32(tboxCarYear.Text) }; 

It will be more typed and visible than using anonymous classes and speakers:

 static void Main(string[] args) { var o = new { Model = "123" }; Foo(o); } static void Foo(dynamic obj) { Console.WriteLine(obj.Model); }