Looping through dictionary object

前端 未结 4 1766
悲哀的现实
悲哀的现实 2020-12-14 14:51

I am very new to .NET, used to working in PHP. I need to iterate via foreach through a dictionary of objects. My setup is an MVC4 app.

The Model looks l

4条回答
  •  鱼传尺愫
    2020-12-14 15:41

    It depends on what you are after in the Dictionary

    Models.TestModels obj = new Models.TestModels();
    
    foreach (var keyValuPair in obj.sp)
    {
        // KeyValuePair
    }
    
    foreach (var key in obj.sp.Keys)
    {
         // Int 
    }
    
    foreach (var value in obj.sp.Values)
    {
        // dynamic
    }
    

提交回复
热议问题