tokei's Profile User Rating: -----

Reputation: 1 Apprentice
Active Members
Active Posts:
53 (0.03 per day)
15-December 11
Profile Views:
Last Active:
User is offline Feb 19 2016 12:32 PM

Previous Fields

Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:

Latest Visitors

Icon   tokei has not set their status

Posts I've Made

  1. In Topic: How to convert to Dictionary<string,object> ?

    Posted 16 Feb 2016


    You'll need a compiler that supports C# 6.0. VS2015 comes with it.

    That's why my compiler ( VS 2013 ) not support it.

    Could you convert @ write it which old compiler read it ?

  2. In Topic: How to convert to Dictionary<string,object> ?

    Posted 16 Feb 2016

    var dict = new Dictionary<int, Dictionary<string, object>> {
                    [1111] = new Dictionary<string, object> {
                        ["Malcolm Reynolds"] = DateTime.Now,
                        ["McDonalds"] = ConsoleColor.Red
                    [2222] = new Dictionary<string, object> {
                        ["Richard"] = "Coffee Maker"
    Error	2	Syntax error, ',' expected

    I copy your code, then found the error. Until now cannot find what the error. Could you help me what the error on your code ? Thanks
  3. In Topic: How to convert to Dictionary<string,object> ?

    Posted 16 Feb 2016


    Even more interesting is that your code that you posted above that you said that works, you'll end up with two items with the same key. How can that satisfy a C# dictionary where the keys are supposed to be unique?

    Look you explain is correct. Tq so much. Let me try your method first.

  4. In Topic: How to convert to Dictionary<string,object> ?

    Posted 15 Feb 2016

    View PostSkydiver, on 16 February 2016 - 02:15 AM, said:

    what does casting have to do with iterating?

    Thanks for your help.

    Before iterate the value, the nest Dictionary will casting to the Dictionary<datatype,datatype> but it goes wrong.
    Below is the code which I found the solution from the internet.

    static void Main(string[] args)
    	Dictionary<string, Dictionary<string, object>> dict = new Dictionary<string, Dictionary<string, object>>();
    	Dictionary<string, object> bar = new Dictionary<string, object>();
    	bar.Add("Malcolm Reynolds", "Ship Captain");
    	bar.Add("McDonalds", "Selling Burger");
    	Dictionary<string, object> bar2 = new Dictionary<string, object>();
    	bar2.Add("Richard", "Coffee Maker");
    	dict.Add("1111", bar);
    	dict.Add("2222", bar2);
    	IterateDictValuesWrong(dict); // wrong way
    static void IterateDictValuesCorrect(Dictionary<string, Dictionary<string, object>> dictValues)
    	Console.WriteLine("IterateDictValuesCorrect method");
    	foreach (var keys in dictValues)
    		string key = keys.Key;
    		Dictionary<string, object> innerDict = keys.Value;
    		foreach (var innerDictValues in innerDict.Values)
    			Console.WriteLine("{0}:{1}", key,innerDictValues);
    static void IterateDictValuesWrong(object values)
    	Console.WriteLine("IterateDictValuesWrong method");
    	// error , cannot casting 
    	Dictionary<string, object> valueDict = (Dictionary<string, object>)values;
    	foreach (var innerDictValues in valueDict)
    		Console.WriteLine("{0}:{1}", innerDictValues.Key, innerDictValues.Value);

    View Postmodi123_1, on 16 February 2016 - 01:53 AM, said:

    ... but do you understand it?

    I try to understand.


    I am leery on your hand waving to gloss over important, but basic, details.. like how to examine the collection with debugging, basic object casting, and reasoning for simple collection design. So it goes..

    Thanks for your help
  5. In Topic: How to convert to Dictionary<string,object> ?

    Posted 15 Feb 2016

    View Postmodi123_1, on 15 February 2016 - 11:20 PM, said:

    Okay - so you dictionary is really string,string and not string, object?

    Why would you need then a super collection of string,dictionary?

    This is just example, any datatype can use.

    I have found the answer from this link http://stackoverflow...-a-foreach-loop

    Thanks for your help.


My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown

Contact Information



tokei hasn't added any friends yet.


tokei has no profile comments yet. Why not say hello?