std::map<> in C#
-
Hi sir, As i am new C#. I developed a code in VC++ where i am reading the data from combo box and storing it in map. As i include header file,i can access
std::map<CString,CString>m_mapId;
std::map<CString,CString>::iterator it=m_mapId.begin();The same code i want to use in C# Any help will be thankful Thanks Raj
-
Hi sir, As i am new C#. I developed a code in VC++ where i am reading the data from combo box and storing it in map. As i include header file,i can access
std::map<CString,CString>m_mapId;
std::map<CString,CString>::iterator it=m_mapId.begin();The same code i want to use in C# Any help will be thankful Thanks Raj
Didn't use C++ much, but I think, you should try Dictionary class.
-
Hi sir, As i am new C#. I developed a code in VC++ where i am reading the data from combo box and storing it in map. As i include header file,i can access
std::map<CString,CString>m_mapId;
std::map<CString,CString>::iterator it=m_mapId.begin();The same code i want to use in C# Any help will be thankful Thanks Raj
The closest thing to this, is probably the SortedDictionary. To do this code, all you'd do is:
SortedDictionary<string,string>_map;
// ... some code to fill the dictionary:
foreach (KeyValuePair<string,string> kvp in _map)
{
// Do something with the data.
}"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Hi sir, As i am new C#. I developed a code in VC++ where i am reading the data from combo box and storing it in map. As i include header file,i can access
std::map<CString,CString>m_mapId;
std::map<CString,CString>::iterator it=m_mapId.begin();The same code i want to use in C# Any help will be thankful Thanks Raj
raju_shiva wrote:
The same code i want to use in C#
Here is the C# code
Dictionary<string, string> hashMap = new Dictionary<string, string>();
IDictionaryEnumerator en = hashMap.GetEnumerator();
while (en.MoveNext())
{
string key = (string)en.Key;
string keyValue = (string)en.Value;
// Do what you want to do with key/value.
}Knock out 't' from can't, you can if you think you can.
-
Hi sir, As i am new C#. I developed a code in VC++ where i am reading the data from combo box and storing it in map. As i include header file,i can access
std::map<CString,CString>m_mapId;
std::map<CString,CString>::iterator it=m_mapId.begin();The same code i want to use in C# Any help will be thankful Thanks Raj
Dictionary m_mapId = new Dictionary();
Dictionary.Enumerator it = m_mapId.GetEnumerator();However, it's unusual to deal with enumerators directly in C# - instead just use a 'foreach' loop, which enumerates for you. David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com -- Modified Wednesday, June 30, 2010 5:36 PM
-
Dictionary m_mapId = new Dictionary();
Dictionary.Enumerator it = m_mapId.GetEnumerator();However, it's unusual to deal with enumerators directly in C# - instead just use a 'foreach' loop, which enumerates for you. David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com -- Modified Wednesday, June 30, 2010 5:36 PM
David Anton wrote:
However, it's unusual to deal with enumerators directly in C# - instead just use a 'foreach' loop, which enumerates for you.
Any example that lets unusual deal of C# enumerators?
Knock out 't' from can't, you can if you think you can. :cool:
-
raju_shiva wrote:
The same code i want to use in C#
Here is the C# code
Dictionary<string, string> hashMap = new Dictionary<string, string>();
IDictionaryEnumerator en = hashMap.GetEnumerator();
while (en.MoveNext())
{
string key = (string)en.Key;
string keyValue = (string)en.Value;
// Do what you want to do with key/value.
}Knock out 't' from can't, you can if you think you can.
Hi sir, Thanks for your reply. I am trying to use as u suggested but getting more confused. Actually i have developed code in VC where i store some values in and store in combo after sorting accordingly. Here is my complete code wt i am doing
/*During initilizing i am strores vaues in map*/
CTest1View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
ResizeParentToFit();m\_mapId\["Abc"\]; m\_mapId\["aa"\];
}
/*any character is typed in edit box*/
CTest1View::OnEditchangeCombo1()
{CString strvalue; CString strTemp; m\_ctrlCombo.GetWindowText(strvalue); //Get the text from combo std::map<CString,CString>::iterator it=m\_mapId.begin();//I will begin using iterator begin m\_ctrlCombo.ResetContent(); for(; it!=m\_mapId.end();it++) // I will loop till the map end { strTemp = it->first; //get the first value from map if(strTemp.Find(strvalue)==0) //find the character in string(which is in map) m\_ctrlCombo.AddString(strTemp); // Add to combo } m\_ctrlCombo.SetWindowText(strvalue); //Get the window text m\_ctrlCombo.ShowDropDown(); //Show the drop down
}
I am trying with C#
Dictionary<string, int> d = new Dictionary<string, int>();
d.Add("aaat", 1); d.Add("aat", 5);
How can i search in map and get the results back in CCombo. Thanks Raj
-
Hi sir, Thanks for your reply. I am trying to use as u suggested but getting more confused. Actually i have developed code in VC where i store some values in and store in combo after sorting accordingly. Here is my complete code wt i am doing
/*During initilizing i am strores vaues in map*/
CTest1View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
ResizeParentToFit();m\_mapId\["Abc"\]; m\_mapId\["aa"\];
}
/*any character is typed in edit box*/
CTest1View::OnEditchangeCombo1()
{CString strvalue; CString strTemp; m\_ctrlCombo.GetWindowText(strvalue); //Get the text from combo std::map<CString,CString>::iterator it=m\_mapId.begin();//I will begin using iterator begin m\_ctrlCombo.ResetContent(); for(; it!=m\_mapId.end();it++) // I will loop till the map end { strTemp = it->first; //get the first value from map if(strTemp.Find(strvalue)==0) //find the character in string(which is in map) m\_ctrlCombo.AddString(strTemp); // Add to combo } m\_ctrlCombo.SetWindowText(strvalue); //Get the window text m\_ctrlCombo.ShowDropDown(); //Show the drop down
}
I am trying with C#
Dictionary<string, int> d = new Dictionary<string, int>();
d.Add("aaat", 1); d.Add("aat", 5);
How can i search in map and get the results back in CCombo. Thanks Raj
raju_shiva wrote:
How can i search in map and get the results back in CCombo.
OK. then you could use HashSet with string as a type. This stores unique values and don't need to have key/value pair.
//Your predefined map values.
HashSet stringSet = new HashSet { "abc", "aa" };//Copy to new array for operations.
string[] stringList = new string[stringSet.Count];
stringSet.CopyTo(stringList);//Suppose you type "a" in combo box edit.
string strValue = "a";//Look for all the values that contains "a"
string[] matchedStrings = Array.FindAll(stringList, delegate(string p)
{
return (p.Contains(strValue));
}//Sort array for correct sequence in combo box.
Array.Sort(matchedStrings);//You should access predefined combox here.
//ComboBox cmbValues = new ComboBox();//Clear all items from combo box.
cmbValues.Items.Clear();//Fill the combo box with selected values.
cmbValues.Items.AddRange(matchedStrings);//default selection to 0th value.
cmbValues.SelectedIndex = 0;
});Hope this gives some idea to you.
Knock out 't' from can't, you can if you think you can. :cool:
-
raju_shiva wrote:
How can i search in map and get the results back in CCombo.
OK. then you could use HashSet with string as a type. This stores unique values and don't need to have key/value pair.
//Your predefined map values.
HashSet stringSet = new HashSet { "abc", "aa" };//Copy to new array for operations.
string[] stringList = new string[stringSet.Count];
stringSet.CopyTo(stringList);//Suppose you type "a" in combo box edit.
string strValue = "a";//Look for all the values that contains "a"
string[] matchedStrings = Array.FindAll(stringList, delegate(string p)
{
return (p.Contains(strValue));
}//Sort array for correct sequence in combo box.
Array.Sort(matchedStrings);//You should access predefined combox here.
//ComboBox cmbValues = new ComboBox();//Clear all items from combo box.
cmbValues.Items.Clear();//Fill the combo box with selected values.
cmbValues.Items.AddRange(matchedStrings);//default selection to 0th value.
cmbValues.SelectedIndex = 0;
});Hope this gives some idea to you.
Knock out 't' from can't, you can if you think you can. :cool:
Hi sir, I tried this code but getting an error as HashSet stringSet = new HashSet { "abc", "aa" }; // "A new expression requires () or [] after type" Thanks Raj
-
Hi sir, I tried this code but getting an error as HashSet stringSet = new HashSet { "abc", "aa" }; // "A new expression requires () or [] after type" Thanks Raj
Actually written code was correct, but due to incorrect formatting, it was not visible. The code line should be as below.
HashSet<string> stringSet = new HashSet<string> { "abc", "aa" };
You could check my previous post in FireFox as below. 1. Select the code. 2. Do right click. 3. select "View Selection Source".
Knock out 't' from can't, you can if you think you can. :cool:
-
Actually written code was correct, but due to incorrect formatting, it was not visible. The code line should be as below.
HashSet<string> stringSet = new HashSet<string> { "abc", "aa" };
You could check my previous post in FireFox as below. 1. Select the code. 2. Do right click. 3. select "View Selection Source".
Knock out 't' from can't, you can if you think you can. :cool:
Hi sir,
Laxman Auti wrote:
HashSet stringSet = new HashSet { "abc", "aa" };
I tried the same ,but stilll the same error Thanks Raj
-
Hi sir,
Laxman Auti wrote:
HashSet stringSet = new HashSet { "abc", "aa" };
I tried the same ,but stilll the same error Thanks Raj
raju_shiva wrote:
I tried the same ,but stilll the same error
Why don't you try something like following?
HashSet<string> hashSet = new HashSet<string>();
hashSet.Add("abc");
hashSet.Add("aa");Knock out 't' from can't, you can if you think you can. :cool:
modified on Monday, July 5, 2010 2:45 PM