keyedcollection

G

GS

please bear with me, I already tried the built-in help, Google but not
finding the solution.

I want to use generic KeyedCollection
first crack
private class RegexHolder
{
String Name;
bool Tested;
RegexOptions regexOption;
String Regex;
String rRemark;
String Groups;
String Category;
String sybRegexList;
protected RegexHolder(String strRegexName, bool bTested,
RegexOptions iRegexOption, String strRegex,
String comment, String strGroups)
{
RegexName = strRegexName;
Tested = bTested;
regexOption = iRegexOption;
Regex = strRegex;
rRemark = comment;
Groups = strGroups;
}
protected int iTested {
get { return (int)Tested; }
}
protected int iRegex
{
get { return (int) regexOption; }
}
};

KeyedCollection<String, RegexHolder> myRegexCollection;
.......
myRegexCollection = new KeyedCollection<String, RegexHolder>
();
and I got complier err about abstract class on the last statement above

So I tried


private class RegexHolder
{
String Name;
/* .... so on like last time around
};


private class myRegexCollection : KeyedCollection<String,
RegexHolder>
{
protected myRegexCollection()
{
KeyedCollection<String, RegexHolder>();
}
protected string GetKeyForItem() {
return item.Name;
}
}
But then I stll get

Error 1 'RegexParse.RegexParse2Csv.myRegexCollection' does not implement
inherited abstract member
'System.Collections.ObjectModel.KeyedCollection<string,RegexParse.RegexParse
2Csv.RegexHolder>.GetKeyForItem(RegexParse.RegexParse2Csv.RegexHolder)'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse2CSV\RegexParse2CSV\RegexP
arse2Csv.cs 62 23 RegexParse2CSV


what did do wrong with GetKeyForItem?
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

GS said:
please bear with me, I already tried the built-in help, Google but not
finding the solution.

I want to use generic KeyedCollection
first crack snip 8<---
KeyedCollection<String, RegexHolder> myRegexCollection;
.......
myRegexCollection = new KeyedCollection<String, RegexHolder>
();
and I got complier err about abstract class on the last statement above

Isn't Dictionary said:
So I tried snip 8<---
protected string GetKeyForItem() {
return item.Name;
}
}
But then I stll get

Error 1 'RegexParse.RegexParse2Csv.myRegexCollection' does not implement
inherited abstract member
'System.Collections.ObjectModel.KeyedCollection<string,RegexParse.RegexParse
2Csv.RegexHolder>.GetKeyForItem(RegexParse.RegexParse2Csv.RegexHolder)'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse2CSV\RegexParse2CSV\RegexP
arse2Csv.cs 62 23 RegexParse2CSV


what did do wrong with GetKeyForItem?

You did not override the existing method, you just made a completely
different method with the same name. You have to use the same signature
as the method that you are overriding:

protected override int GetKeyForItem(RegexHolder item)
 
G

GS

Thank you. So I tried your suggestion and I still get error

Error 2
'System.Collections.Generic.Dictionary<string,RegexParse.RegexParse2Csv.Rege
xHolder>' is a 'type' but is used like a 'variable'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse2CSV\RegexParse2CSV\RegexP
arse2Csv.cs 87 17 RegexParse2CSV

private class RegexHolder
{
public String Name; // had to change scope to allow the
regexcollection to access Name - suppose I could provide public get
....
}

private class myRegexCollection : KeyedCollection<String, RegexHolder>
{
protected myRegexCollection()
{
KeyedCollection<String, RegexHolder>(); //compiler
complained about the <String, RegexHolder>
// compiler does not like RegexHolder
}
protected override String GetKeyForItem(RegexHolder item)
{
return item.Name;
}
}

I thought I was was supposed to use a type not variable but I must have
misunderstood something again

I tired something else hoping it wil help but same error
private class myRegexCollection : KeyedCollection<String, RegexHolder>
{
protected myRegexCollection(RegexHolder rh) // added
argument even though ti doesnot make sense to to me
// because I should be able to create an empty class to add
item to it
{
KeyedCollection<String, RegexHolder>(rh);
}
protected override String GetKeyForItem(RegexHolder item)
{
return item.Name;
}
}

Same thing with dictionary instead of KeydCollection
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

GS said:
Thank you. So I tried your suggestion and I still get error

Error 2
'System.Collections.Generic.Dictionary<string,RegexParse.RegexParse2Csv.Rege
xHolder>' is a 'type' but is used like a 'variable'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse2CSV\RegexParse2CSV\RegexP
arse2Csv.cs 87 17 RegexParse2CSV

private class RegexHolder
{
public String Name; // had to change scope to allow the
regexcollection to access Name - suppose I could provide public get
....
}

private class myRegexCollection : KeyedCollection<String, RegexHolder>
{
protected myRegexCollection()
{
KeyedCollection<String, RegexHolder>(); //compiler
complained about the <String, RegexHolder>
// compiler does not like RegexHolder
}
protected override String GetKeyForItem(RegexHolder item)
{
return item.Name;
}
}

I thought I was was supposed to use a type not variable but I must have
misunderstood something again

I tired something else hoping it wil help but same error
private class myRegexCollection : KeyedCollection<String, RegexHolder>
{
protected myRegexCollection(RegexHolder rh) // added
argument even though ti doesnot make sense to to me
// because I should be able to create an empty class to add
item to it
{
KeyedCollection<String, RegexHolder>(rh);
}
protected override String GetKeyForItem(RegexHolder item)
{
return item.Name;
}
}

Same thing with dictionary instead of KeydCollection

If you use a dictionary then you don't have to create your own
collection class. A dictionary is not an abstract class.
 
B

Ben Voigt

GS said:
Thank you. So I tried your suggestion and I still get error

Error 2
'System.Collections.Generic.Dictionary<string,RegexParse.RegexParse2Csv.Rege
xHolder>' is a 'type' but is used like a 'variable'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse2CSV\RegexParse2CSV\RegexP
arse2Csv.cs 87 17 RegexParse2CSV

private class RegexHolder
{
public String Name; // had to change scope to allow the
regexcollection to access Name - suppose I could provide public get
....
}

private class myRegexCollection : KeyedCollection<String, RegexHolder>
{
protected myRegexCollection()
{
KeyedCollection<String, RegexHolder>(); //compiler
complained about the <String, RegexHolder>

That's not how you call a base constructor in C#. Try

protected myRegexCollection()
: base()
{}
 
G

GS

wonderful. thank you very much for teaching me this very useful concept I
missed.

however complier complained after I replaced
KeyedCollection<String, RegexHolder>();
with
base();

Error 2 Use of keyword 'base' is not valid in this context
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse2CSV\RegexParse2CSV\RegexP
arse2Csv.cs 88 17 RegexParse2CSV



any other tips of non c# programmer/developer?
 
G

GS

pardon me, I misread your tip. after adjusted correctly, it works.


wonderful. thank you.


However if you happen to have tips or known common for non c# people, I
would love to see them Thank you again.
 
B

Ben Voigt

GS said:
pardon me, I misread your tip. after adjusted correctly, it works.


wonderful. thank you.


However if you happen to have tips or known common for non c# people, I
would love to see them Thank you again.

What language are you most familiar with? The "tricky" parts of C# vary
from person to person, largely because what they expect depends on what they
have experience using.
 
Top