473,326 Members | 2,111 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,326 software developers and data experts.

Why did you invent "Generics Functions" like this?

Why did you devise invoking generics functions like you did?
I understand that the method of use is "compatible" to that of generic classes
but isn't it a bit clumsy? Or am I missing something?

Wouldn't it have been "cooler" to have just been able to invoke a generic method
without having to state which type you want to use it with (in questionable
cases one could always revert to type casting)? The paramaters would be
suffictient to identify the type wouldn't they?

Generic Funtion:
public ItemType GenericFunction<ItemType>(ItemType
item)
{
// (Process item here.)
return item;
}
The code that calls GenericFunction() defines the type, which is then used for a
parameter to the function and a method.

way to invoke at the time:
string input = "...";
string output = Obj.GenericFunction<string>(input);

how about this?
string input = "...";
// input is string, so thats the type to use...
string output = Obj.GenericFunction(input);
Nov 16 '05 #1
1 1387
Robert Heuvel <ro***********@isopass.com> wrote in
news:u#**************@TK2MSFTNGP11.phx.gbl:
Why did you devise invoking generics functions like you did?
I understand that the method of use is "compatible" to that of generic
classes but isn't it a bit clumsy? Or am I missing something?

Wouldn't it have been "cooler" to have just been able to invoke a
generic method without having to state which type you want to use it
with (in questionable cases one could always revert to type casting)?
The paramaters would be suffictient to identify the type wouldn't
they?

<snip>

The C# 2.0 language specification, available here:
http://msdn.microsoft.com/vcsharp/te...e/default.aspx

Section 19.1.5 states that:

"...In many cases, however, the compiler can deduce the correct type
argument from the other arguments passed to the method, using a process
called *type inferencing*..."

* added to denote emphasized text in original. This is exactly what
you're referring to.

Example:

public T Foo<T>(T value)
{
...
}

String s = Foo("Hello world");
Int32 i = Foo(10);

this, according to the spec, should work as you expect it to, where the
first call to Foo would call Foo<String> and the second call would use
Foo<Int32>.

--
Lasse Vågsæther Karlsen
la***@vkarlsen.no
PGP KeyID: 0x0270466B
Nov 16 '05 #2

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

Similar topics

6
by: Rick | last post by:
Hello all. I have an index.php file that has a lot of functions that I wrote. Let's say for the sake of argument that there are 1000 functions of 100 lines each. The index.php file is invoked...
3
by: elektrophyte | last post by:
I was looking at the PHP function "call_user_func()" (http://us3.php.net/call_user_func). It appears that this will solve a design problem in the app I'm working on. (I'm writing a class that will...
4
by: Pelle Beckman | last post by:
Hi, I read a tutorial on function pointers in a swedish computer magazine. The author used functions named dlopen() and dlsym() (found in "dlfcn.h" under linux) that gave him the ability to get...
9
by: rnn98 | last post by:
hi, my multithread application, running under solaris box, is crashing eventually. I tried to spot and substitute functions not "thread safe", but I guess my search wasn't good enough. I have put...
5
by: active | last post by:
In windows XP and VB.NET should the "W" functions in the Windows API be used or should the "A" functions be used I'm looking at a type library and see things like the following: #ifdef...
4
by: dougans | last post by:
Hey there, Hope someone can help me, completely stuck with immigrating from php4 to OOP based php5. == index.php -- include(database.inc.php);
1
by: Mikewill | last post by:
I need to fix my Moodle database and someone has told me that they "used their server's CPanel and the mySQL feature to "check" then "fix" his moodle database". I dont have a cpanel and was hoping...
3
by: Zerozone | last post by:
I mean : How can C write these functions... I would like to know it, so you can show me where can I find about this infomation ?
2
by: Martin Robins | last post by:
Marc has sorted my problem with the collections, however I am now in a new scenario; I am trying to compare a generic property value before setting it as shown below ... public T Value { get {...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.