The following code example demonstrates how to use ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) to create a Dictionary<TKey,TValue> by using a key selector. C# Copy class Package { public string Company { get; set; } public double Weight { get; set; } publi...
}this.Modifiers = modifiers.ToDictionary<IModifier,string>(i => i.Target);// Merge sections that descend from other sections. This means that the hierarchy does not// need to be negotiated when looking up rules in a section. For example, if you have some// generic "Move" rules and the...
First example. Building up dictionaries can require a significant amount of code. When we use ToDictionary, we can use less code to create a Dictionary. Part 1 We initialize an array of 4 integers, all odd numbers. These ints will be used to create a Dictionary. Part 2 We invoke To...
This simple example builds a list of cars. We then get this list in Main(), and assign it to the variable "cars". Then we use type inference and assign to dictionary the value returned from the ToDictionary() extension method. This method returns a IDictionary(Of K, V), and in this...
The following code example demonstrates how to use ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) to create a Dictionary<TKey,TValue> by using a key selector. C# Copy class Package { public string Company { get; set; } public double Weight { get; set; } publi...
The following code example demonstrates how to use ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) to create a Dictionary<TKey,TValue> by using a key selector. C# Kopyahin class Package { public string Company { get; set; } public double Weight { get; set; } ...
For example, consider the following code:csharpcode Copy Class Car Public id As Integer Public manufacturer As String Public color As String End Class Function GetCars() As List(Of Car) Dim ret = New List(Of Car) ret.Add(New Car With {.id = 1, .manufacturer = "Toyota", .color =...
The following code example demonstrates how to use ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) to create a Dictionary<TKey,TValue> by using a key selector. C# Copy class Package { public string Company { get; set; } public double Weight { get; set; } publi...
The following code example demonstrates how to use ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) to create a Dictionary<TKey,TValue> by using a key selector. C# Copy class Package { public string Company { get; set; } public double Weight { get; set; } publi...
The following code example demonstrates how to use ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) to create a Dictionary<TKey,TValue> by using a key selector. C# Copy class Package { public string Company { get; set; } public double Weight { get; set; } publi...