Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
I'm trying to do the follwoing but having an error " Cannot implicitly convert type 'string'to 'System.Collections.Generic.Dictionary<string,string>'"
public  Dictionary<string,> ReasonErrorCodeList
        {
            set
            {
                if (_list.Count> 0)
                {
                  foreach (KeyValuePair<string,> pair in _list)
                  {
                      _list.Add(pair.Key,"1234");
                         
                      
                  }
                  string x = _list.ToString();
                    //string y = _list.
                  infoMessage.Text = string.Format("the list is ",x);
                  infoPanel.Visible = true;
                }
            }
            
            get { 
                
           
                //_list.Add (infoMessage.Text,"ERR_OOOOO1");
                return infoMessage.Text;
            }
         
        }
 

        
          /// Auto-generated field.
         /// To modify move field declaration from designer file to code-behind file.
   
        protected global::System.Web.UI.WebControls.Literal infoMessage;
Posted 31-Oct-11 6:41am
rajh7423
Edited 31-Oct-11 6:43am
Mehdi Gholam236.9K
v2
Comments
Richard MacCutchan at 31-Oct-11 12:48pm
   
Which line gives the error? Please don't leave it to people to guess where it occurs.
Nishant Sivakumar at 31-Oct-11 13:15pm
   
The get-method in the property.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Assuming _list is a Dictionary<string, string> why are you calling ToString on it? What do you think will that give you?
 
Also in the setter, you iterate through the dictionary and add items to itself (pointless thing to do).
 
The error in the get-method is obvious. You cannot return a String when the expected return type is a Dictionary<>.
  Permalink  
v2
Comments
Richard MacCutchan at 31-Oct-11 13:29pm
   
Obvious when you look at the code carefully, which I obviously didn't. However I still feel my prompt to OP was valid.
Nishant Sivakumar at 31-Oct-11 13:32pm
   
Yes it certainly was. I am just better than most people at figuring out what people are trying to say :-)
Nishant Sivakumar at 31-Oct-11 13:34pm
   
I meant your response was certainly valid. The OP was quite vague in his description.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 410
1 Gihan Liyanage 338
2 ChauhanAjay 180
3 Vinay Mistry 160
4 Sergey Alexandrovich Kryukov 138
0 Sergey Alexandrovich Kryukov 9,011
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 31 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100