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

Generic, Delegate, void

Hi all!

I found a problem when using generic with delegate:

delegate RT MethodTemplate <RT> ();
delegate RT MethodTemplate <RT, AT0> (AT0 a0);
delegate RT MethodTemplate <RT, AT0, AT1> (AT0 a0, AT1 at1);
delegate RT MethodTemplate <RT, AT0, AT1, AT2> (AT0 a0, AT1 at1, AT2
at2);

The definition is fine, but:

MethodTemplate<void> someAnonymousMethod = delegate () { .... };

gives me """ Keyword 'void' cannot be used in this context """
I know void is not a type, but isn't this inconsistent??

Nov 16 '05 #1
3 2532
Aquila,

Why is it inconsistent? Why would you expect that you can use void with
this? It kind of doesn't make sense to be able to pass void to a Generic,
because you could have easily written the class/method without the Generic
parmameter in order to indicate void is being passed.

What are you trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Aquila Deus" <aq*********@yahoo.co.uk> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Hi all!

I found a problem when using generic with delegate:

delegate RT MethodTemplate <RT> ();
delegate RT MethodTemplate <RT, AT0> (AT0 a0);
delegate RT MethodTemplate <RT, AT0, AT1> (AT0 a0, AT1 at1);
delegate RT MethodTemplate <RT, AT0, AT1, AT2> (AT0 a0, AT1 at1, AT2
at2);

The definition is fine, but:

MethodTemplate<void> someAnonymousMethod = delegate () { .... };

gives me """ Keyword 'void' cannot be used in this context """
I know void is not a type, but isn't this inconsistent??

Nov 16 '05 #2

Nicholas Paldino [.NET/C# MVP] wrote:
Aquila,

Why is it inconsistent? Why would you expect that you can use void with this? It kind of doesn't make sense to be able to pass void to a Generic, because you could have easily written the class/method without the Generic parmameter in order to indicate void is being passed.

What are you trying to do?
What I want is a set of general generic delegates so that I can easily
declare anonymous functions and use delegates in object members and
function parameters.

Without void in generics I have to give generic delegate/function that
returns void a different name.



--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Aquila Deus" <aq*********@yahoo.co.uk> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Hi all!

I found a problem when using generic with delegate:

delegate RT MethodTemplate <RT> ();
delegate RT MethodTemplate <RT, AT0> (AT0 a0);
delegate RT MethodTemplate <RT, AT0, AT1> (AT0 a0, AT1 at1);
delegate RT MethodTemplate <RT, AT0, AT1, AT2> (AT0 a0, AT1 at1, AT2 at2);

The definition is fine, but:

MethodTemplate<void> someAnonymousMethod = delegate () { .... };

gives me """ Keyword 'void' cannot be used in this context """
I know void is not a type, but isn't this inconsistent??


Nov 16 '05 #3

Aquila Deus wrote:
Nicholas Paldino [.NET/C# MVP] wrote:
Aquila,

Why is it inconsistent? Why would you expect that you can use void with
this? It kind of doesn't make sense to be able to pass void to a

Generic,
because you could have easily written the class/method without the

Generic
parmameter in order to indicate void is being passed.

What are you trying to do?


What I want is a set of general generic delegates so that I can

easily declare anonymous functions and use delegates in object members and
function parameters.

Without void in generics I have to give generic delegate/function that returns void a different name.


For example, you can use:
someEvent += new MethodTemplate<object, EventArgs>(myEventHandler);
instead of:
someEvent += new EventHandler(myEventHandler);
which requires you declare a new delegate type for each set of function
parameters and return types.

Nov 16 '05 #4

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

Similar topics

6
by: David Veeneman | last post by:
I have several events that pass a value in their event args. One event passes an int, another a string, another a DateTime, and so on. Rather than creating a separate set of event args for each...
7
by: Bill Woodruff | last post by:
I've found it's no problem to insert instances of named delegates as values into a generic dictionary of the form : private Dictionary<KeyType, DelegatemyDictionary = new Dictionary<KeyType,...
7
by: Dave | last post by:
I've got these declarations: public delegate void FormDisplayResultsDelegate<Type>(Type displayResultsValue); public FormDisplayResultsDelegate<stringdisplayMsgDelegate; instantiation:...
26
by: raylopez99 | last post by:
Here is a good example that shows generic delegate types. Read this through and you'll have an excellent understanding of how to use these types. You might say that the combination of the generic...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.