469,364 Members | 2,332 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,364 developers. It's quick & easy.

keyedcollection

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, RegexHoldermyRegexCollection;
.......
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<st ring,RegexParse.RegexParse
2Csv.RegexHolder>.GetKeyForItem(RegexParse.RegexPa rse2Csv.RegexHolder)'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse 2CSV\RegexParse2CSV\RegexP
arse2Csv.cs 62 23 RegexParse2CSV
what did do wrong with GetKeyForItem?

May 26 '07 #1
8 3558
GS wrote:
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, RegexHoldermyRegexCollection;
.......
myRegexCollection = new KeyedCollection<String, RegexHolder>
();
and I got complier err about abstract class on the last statement above
Isn't Dictionary<String, RegexHolderwhat you really want?
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<st ring,RegexParse.RegexParse
2Csv.RegexHolder>.GetKeyForItem(RegexParse.RegexPa rse2Csv.RegexHolder)'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse 2CSV\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öran Andersson
_____
http://www.guffa.com
May 26 '07 #2
GS
Thank you. So I tried your suggestion and I still get error

Error 2
'System.Collections.Generic.Dictionary<string,Rege xParse.RegexParse2Csv.Rege
xHolder>' is a 'type' but is used like a 'variable'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse 2CSV\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
May 26 '07 #3
GS wrote:
Thank you. So I tried your suggestion and I still get error

Error 2
'System.Collections.Generic.Dictionary<string,Rege xParse.RegexParse2Csv.Rege
xHolder>' is a 'type' but is used like a 'variable'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse 2CSV\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.

--
Göran Andersson
_____
http://www.guffa.com
May 26 '07 #4

"GS" <gs**********************@msnews.Nomail.comwrote in message
news:uu**************@TK2MSFTNGP05.phx.gbl...
Thank you. So I tried your suggestion and I still get error

Error 2
'System.Collections.Generic.Dictionary<string,Rege xParse.RegexParse2Csv.Rege
xHolder>' is a 'type' but is used like a 'variable'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse 2CSV\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()
{}

// 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


May 28 '07 #5
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\RegexParse 2CSV\RegexParse2CSV\RegexP
arse2Csv.cs 88 17 RegexParse2CSV

any other tips of non c# programmer/developer?
"Ben Voigt" <rb*@nospam.nospamwrote in message
news:O2**************@TK2MSFTNGP03.phx.gbl...
>
"GS" <gs**********************@msnews.Nomail.comwrote in message
news:uu**************@TK2MSFTNGP05.phx.gbl...
Thank you. So I tried your suggestion and I still get error

Error 2
'System.Collections.Generic.Dictionary<string,Rege xParse.RegexParse2Csv.Rege
xHolder>' is a 'type' but is used like a 'variable'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse 2CSV\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()
{}

// 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


May 28 '07 #6
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.

"Ben Voigt" <rb*@nospam.nospamwrote in message
news:O2**************@TK2MSFTNGP03.phx.gbl...
>
"GS" <gs**********************@msnews.Nomail.comwrote in message
news:uu**************@TK2MSFTNGP05.phx.gbl...
Thank you. So I tried your suggestion and I still get error

Error 2
'System.Collections.Generic.Dictionary<string,Rege xParse.RegexParse2Csv.Rege
xHolder>' is a 'type' but is used like a 'variable'
D:\data\IeI\gp\AppCom\IeStringClassProd\RegexParse 2CSV\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()
{}

// 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


May 28 '07 #7

"GS" <gs**********************@msnews.Nomail.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
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.
May 29 '07 #8
GS
thank you for reply.

vb, powerbuilder are the languages I am familiar with
"Ben Voigt" <rb*@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>
"GS" <gs**********************@msnews.Nomail.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
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.


May 30 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by James T. | last post: by
reply views Thread by Craig Buchanan | last post: by
3 posts views Thread by Wiebe Tijsma | last post: by
10 posts views Thread by Chris Mullins [MVP] | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.