Quick question – less verbose syntax possible for this static KeyValuePair[] initialization?

Hey guys! Is it possible to do this initialization with more compact code?

 KeyValuePair<PlanemoObject.MainType, float>[] weights = { new KeyValuePair<PlanemoObject.MainType, float>(PlanemoObject.MainType.Dwarf, 1f), new KeyValuePair<PlanemoObject.MainType, float>(PlanemoObject.MainType.Earth, 3f), new KeyValuePair<PlanemoObject.MainType, float>(PlanemoObject.MainType.SuperEarth, 2f), new KeyValuePair<PlanemoObject.MainType, float>(PlanemoObject.MainType.GasGiant, 3f), new KeyValuePair<PlanemoObject.MainType, float>(PlanemoObject.MainType.SuperGiant, 1f) }; 

Much appreciated if anyone has a simpler way to do this, as I need to make a lot of similar arrays.

by Ryahes via /r/csharp

Leave a Reply