How to declare function that accepts any generic list as input
parameter? I mean I need
void foo(List<list)
{
}
where:
Valid parameters are List<SomeInfo>, List<string>, List<Guid>, e.t.c.
Invalid parameters are SomeInfo[], string[], Array, ArrayList,
Dictionary<int, string>, e.t.c
Is it possible?
TIA,
Mykola http://marss.co.ua 4 3170
On Nov 1, 8:29 am, marss <marss...@gmail.comwrote:
How to declare function that accepts any generic list as input
parameter? I mean I need
void foo(List<list)
{}
where:
Valid parameters are List<SomeInfo>, List<string>, List<Guid>, e.t.c.
Invalid parameters are SomeInfo[], string[], Array, ArrayList,
Dictionary<int, string>, e.t.c
Is it possible?
Yes - you need to make the method generic:
void Foo<T>(List<Tlist)
{
}
Jon
On 1 , 10:50, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Nov 1, 8:29 am, marss <marss...@gmail.comwrote:
How to declare function that accepts any generic list as input
parameter? I mean I need
void foo(List<list)
{}
where:
Valid parameters are List<SomeInfo>, List<string>, List<Guid>, e.t.c.
Invalid parameters are SomeInfo[], string[], Array, ArrayList,
Dictionary<int, string>, e.t.c
Is it possible?
Yes - you need to make the method generic:
void Foo<T>(List<Tlist)
{
}
Jon
Thanks
Valid parameters are List<SomeInfo>, List<string>, List<Guid>, e.t.c.
Invalid parameters are SomeInfo[], string[], Array, ArrayList,
For info, if you want it to additionally work with arrays [i.e. T[],
not Array], (typed) collections, etc - then another option is to use
the less specific IList<Tinterface:
void Foo<T>(IList<Tlist)
{
}
This obviously won't give you as many methods etc as List<T>, but it
should allow most options. In .NET 3.5, extension methods (in
System.Linq) mean that IList<Texposes almost as much functionality
as List<Tdoes (albeit via subtly different implementation).
Marc
On 1 , 10:58, Marc Gravell <marc.grav...@gmail.comwrote:
Valid parameters are List<SomeInfo>, List<string>, List<Guid>, e.t.c.
Invalid parameters are SomeInfo[], string[], Array, ArrayList,
For info, if you want it to additionally work with arrays [i.e. T[],
not Array], (typed) collections, etc - then another option is to use
the less specific IList<Tinterface:
void Foo<T>(IList<Tlist)
{
}
This obviously won't give you as many methods etc as List<T>, but it
should allow most options. In .NET 3.5, extension methods (in
System.Linq) mean that IList<Texposes almost as much functionality
as List<Tdoes (albeit via subtly different implementation).
Marc
Thanks for suggestion This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: tropostropos |
last post by:
On Solaris, using the Sun compiler, I get annoying warnings from the
following code. The problem is that I am passing a C++ member function
pointer to the C library function qsort. Is there a...
|
by: Harshankumar |
last post by:
Hello,
I have the following questions
1) can we pass the parameters to interrupt?
2)can we return the parameters from interrupt
Regards
harshan
|
by: Dotnet Gruven |
last post by:
I've posted this in the adonet group, however it was suggested I might have
better luck here....
=============================================================
I'm trying to use a typed dataset and...
|
by: eric |
last post by:
Can I declare a pure virtual member function which accepts as input a
boost shared pointer to an object of a base class, such that
- concrete implementations of the function can redirect the...
|
by: neilcancer |
last post by:
My English is poor...
There are some sort algorithms which sort a sequencial list. The
sequencial list was defined in "list-seq.h".
sort_and_time() accepts one of these sort functions. It uses...
|
by: Beta What |
last post by:
Hello,
I have a question about casting a function pointer. Say I want to make
a generic module (say some ADT implementation) that requires a function
pointer from the 'actual/other modules'...
|
by: Fabrizio Romano |
last post by:
Hello,
I have a problem with a generic method.
I have written a sieve to generate prime numbers. This method takes an input
parameter which is the upperbound of the last prime I need to get. So...
|
by: Jon Slaughter |
last post by:
I have some code like
if (val.GetType().Name == typeof(List<>).Name)
{
}
which lets me determine if val is a generic list(I've already taken care of
the non-generic part but I'd rather be...
|
by: Daniel |
last post by:
I'm getting an error on this code that says index out of range. It's an
unhandled exception error. What is the problem?
List<unsigned intls(1000);
ls = u ;
Daniel
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |