var dictionary = new Dictionary(); dictionary.Add("apple", 3); dictionary.Add("orange", 5); int count = dictionary["apple"];
public class MyOptions { public string ConnectionString {get;set;} } var options = Options.Create(new MyOptions { ConnectionString = "mydb" }); string connectionString = options.Value.ConnectionString;
public class Order { public int Id {get;set;} public string Product {get;set;} } public class OrderDto { public int Id {get;set;} public string ProductName {get;set;} } var config = new MapperConfiguration(cfg => { cfg.CreateMapThis example uses AutoMapper to map an Order object to an OrderDto object. It creates a MapperConfiguration object and defines a mapping between the Order and OrderDto classes. It then instantiates an Order object and a mapper object, and calls the Map() method to convert the Order object to the OrderDto object. Package library: AutoMapper.() .ForMember(dest => dest.ProductName, opt => opt.MapFrom(src => src.Product)); }); var order = new Order { Id = 1, Product = "iPhone" }; var mapper = config.CreateMapper(); var dto = mapper.Map (order);