473,386 Members | 1,864 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,386 software developers and data experts.

MyJaggedIntArr(ICollection<ICollection<int>> items) rejects List<List<Int>>

Hi,

*background*
I want a class containing an int[][] (a list of sets of integer). This
should be hidden for the user and he/she should be able to insert
his/her favourite data structure so to be a little fancy I thought I'd
do a Ctor like this:

// this is the "core": private int[][] sets;

public MyJaggedIntArr(ICollection<ICollection<int>items)
{
this.sets = new int[items.Count][];
int c = 0;
foreach (ICollection<intset in items)
{
sets[c] = new int[set.Count];
set.CopyTo(sets[c++], 0);
}
}

*the problem*
This works fine if I insert an int[][] into the Ctor, but I was unable
to pass a List<List<Int>I got the following exception:

Argument '1': cannot convert from
'System.Collections.Generic.List<System.Collection s.Generic.List<int>>'
to
'System.Collections.Generic.ICollection<System.Col lections.Generic.ICollection<int>>'

*the question*
Is there some even more basic interface than ICollection that includes
lists and ICollection that I could use? Or should I just make four
constructors?

1 - List<List<Int>>
2 - List<ICollection<Int>>
3 - ICollection<List<Int>>
4 - ICollection<ICollection<Int>>

I also might need to add a fifth one
(5 - int[,])

Or should I just force the user to insert int[][]?

thanks

/Per

Dec 19 '06 #1
2 2217
Hello,

If the users will always be adding int[][] then I would force that. Do
they really need the ability to add generic lists of ints?

--
Cheers,
Gary
http://www.garyshort.org/
per9000 wrote:
Hi,

*background*
I want a class containing an int[][] (a list of sets of integer). This
should be hidden for the user and he/she should be able to insert
his/her favourite data structure so to be a little fancy I thought I'd
do a Ctor like this:

// this is the "core": private int[][] sets;

public MyJaggedIntArr(ICollection<ICollection<int>items)
{
this.sets = new int[items.Count][];
int c = 0;
foreach (ICollection<intset in items)
{
sets[c] = new int[set.Count];
set.CopyTo(sets[c++], 0);
}
}

*the problem*
This works fine if I insert an int[][] into the Ctor, but I was unable
to pass a List<List<Int>I got the following exception:

Argument '1': cannot convert from
'System.Collections.Generic.List<System.Collection s.Generic.List<int>>'
to
'System.Collections.Generic.ICollection<System.Col lections.Generic.ICollection<int>>'

*the question*
Is there some even more basic interface than ICollection that includes
lists and ICollection that I could use? Or should I just make four
constructors?

1 - List<List<Int>>
2 - List<ICollection<Int>>
3 - ICollection<List<Int>>
4 - ICollection<ICollection<Int>>

I also might need to add a fifth one
(5 - int[,])

Or should I just force the user to insert int[][]?

thanks

/Per
Dec 19 '06 #2
If the users will always be adding int[][] then I would force that. Do
they really need the ability to add generic lists of ints?
Hi Gary,
since I don't know how users will store their int's I'd be happy to
find something generic. Also int[][] is an implementation of
ICollection<ICollection<Int>so the Ctor above can deal with it.

But on the other hand: do they really need a very generic constructor?
No, probably not.

Also I would like the user to not know/care about how I store the int's
since they might get funny ideas (I know I get them all the time).

There is really little trouble for me to write N^2 Constructors. But it
really intrigued me that List<Twas *not* an implementation of
ICollection<Tso it is also a philosophical/structural question.

/Per

Dec 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Donnal Walter | last post by:
The following method is defined in one of my classes: def setup(self, items={}): """perform setup based on a dictionary of items""" if 'something' in items: value = items # now do something...
4
by: mb | last post by:
what is the best way to do this: In a game I want to a class called "Items". This class will have the game items public class Items { public int Chair public int Table . . .and so on . . .
9
by: Alpha | last post by:
Hi, How can I set all the items in a listbox to be selected? I can't find a property or mehtod to do it so I thought I'll try using setselected method but I need to find out how many items are in...
2
by: dave | last post by:
This little problem is driving me nuts!! On my webform page I create 2 variables.. Protected p_dml As String = "I" Public Const mwv_id As Integer = 0 ' originally had mwv_id as Protected
21
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each...
2
by: hsuntn | last post by:
I am grabbing Outlook MailItems using the Items property on my Outlook inbox. When I iterate through them, I notice that they are not ordered in ReceivedTime or CreationTime order. For example, ...
0
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
13
by: PetterL | last post by:
I writing a program where I read menu items from a file. But I have problem when I click an menu item i want it to mark that one as checked but I cant access the menu object of that item to see...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.