fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. var dicionario = new Dictionary<string, MyObject> {
  7. ["item1"] = new MyObject("item1", "valor1", 1, 1.1),
  8. ["item2"] = new MyObject("item2", "valor2", 2, 2.2),
  9. ["item3"] = new MyObject("item3", "valor3", 3, 3.3)
  10. };
  11. Console.WriteLine(dicionario["item2"].Value);
  12. }
  13. }
  14.  
  15. public class MyObject {
  16. public string Name {get; set;}
  17. public string Value {get; set;}
  18. public int Prop1 {get; set;}
  19. public double Prop2 {get; set;}
  20.  
  21. public MyObject (string name, string valueParam, int prop1, double prop2){
  22. this.Name = name;
  23. this.Value = valueParam;
  24. this.Prop1 = prop1;
  25. this.Prop2 = prop2;
  26. }
  27. }
  28.  
  29. //https://pt.stackoverflow.com/q/257902/101
Success #stdin #stdout 0.02s 15980KB
stdin
Standard input is empty
stdout
valor2