473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 3739
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason Kendall | last post by:
Specifically, I would like a Generic dynamic list that supports referencing items by Index and by Key. I've looked at List(of T), System.Collections.Generic.Dictionary(of Key, Value) and others...
0
by: James T. | last post by:
Hello! How I can update an object in KeyedCollection. whileItem propery is Read Only? Thank you! James
4
by: Martin Widmer | last post by:
Hi folks. I am using this collection class: Public Class ContentBlocksCollection Inherits DictionaryBase 'Object variables for attributes 'Attributes Default Public Property Item(ByVal...
0
by: Craig Buchanan | last post by:
is there an easy way to serialize on the keys in a KeyedCollection, rather than the entire collection of objects? perhaps there is another option? thanks for your time.
9
by: Terry | last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces. One of the major uses is to be able to split out Read-only access to an obect. Let me give you a simple (contrived)...
3
by: Brannon | last post by:
So when you use VS's View Designer, each object included is keyed off its Name. You cannot make the name the same as some other component. You can change the name in a PropertyGrid. I want to do a...
3
by: Wiebe Tijsma | last post by:
Hi, I'm trying to serialize a KeyedCollection with the SoapFormatter, however I'm getting the exception: System.Runtime.Serialization.SerializationException: Soap Serializer does not support...
10
by: Chris Mullins [MVP] | last post by:
KeyedCollection is a very handy little class, that unforutnatly has a nasty bug in it. The bug (which I ran across) causes the following code to fail: if (!rooms.Contains(room))...
9
by: bchirra | last post by:
Can I sort a KeyedCollection? If so how do I do it. Please, any help on this issue is very much appreciated. Thank you.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.