c# - Easy way to Print Values of a dictionary? -


i have below code:

static void main(string[] args) {     // add 5 employees dictionary.     var employees = new dictionary<int, employee>();     employees.add(1, new employee(1, "john"));     employees.add(2, new employee(2, "henry"));     employees.add(3, new employee(3, "jason"));     employees.add(4, new employee(4, "ron"));     employees.add(5, new employee(5, "yan")); } 

is there easy way print values of dictionaries in easy way in java? example, want able print like:

employee key 1: id=1, name= john

employee key 2: id=2, name= henry

.. etc..

thank you.

sorry, used java!

you can use foreach statement:

foreach(var pair in employees) {     console.writeline($"employee key {pair.key}: id={pair.value.id} name={pair.value.name}"); } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -