Click here to Skip to main content
15,919,341 members
Home / Discussions / C#
   

C#

 
GeneralRe: use debug info from external application Pin
Roland Bär1-Jul-05 5:48
Roland Bär1-Jul-05 5:48 
GeneralRe: use debug info from external application Pin
S. Senthil Kumar1-Jul-05 6:07
S. Senthil Kumar1-Jul-05 6:07 
GeneralRe: use debug info from external application Pin
Piovra_6-Jul-05 2:13
Piovra_6-Jul-05 2:13 
GeneralExtending xml comment intellisense Pin
Roland Bär1-Jul-05 3:42
Roland Bär1-Jul-05 3:42 
Questionhow to get wsdl using wse 2.0 in short Pin
Iftikhar Akram1-Jul-05 3:36
Iftikhar Akram1-Jul-05 3:36 
AnswerRe: how to get wsdl using wse 2.0 in short Pin
Member 122691721-Jul-05 19:23
Member 122691721-Jul-05 19:23 
GeneralRe: how to get wsdl using wse 2.0 in short Pin
4-Jul-05 3:09
suss4-Jul-05 3:09 
QuestionAre there any issues with connecting to the ORACLE 10g database through C# .Net? Pin
suvarna joshi1-Jul-05 3:16
suvarna joshi1-Jul-05 3:16 
GeneralUrgent Integration of Windows Service setup with my project Pin
ksanju10001-Jul-05 1:50
ksanju10001-Jul-05 1:50 
GeneralEvent fired on killing an application fromTaskManager Pin
manivannan.p1-Jul-05 1:44
manivannan.p1-Jul-05 1:44 
GeneralRe: Event fired on killing an application fromTaskManager Pin
Dave Kreskowiak1-Jul-05 3:46
mveDave Kreskowiak1-Jul-05 3:46 
GeneralRe: Event fired on killing an application fromTaskManager Pin
manivannan.p1-Jul-05 22:12
manivannan.p1-Jul-05 22:12 
GeneralRe: Event fired on killing an application fromTaskManager Pin
Dave Kreskowiak2-Jul-05 16:31
mveDave Kreskowiak2-Jul-05 16:31 
GeneralRational for Generics? Proposal for change Pin
Nick Hounsome1-Jul-05 0:10
Nick Hounsome1-Jul-05 0:10 
GeneralRe: Rational for Generics? Proposal for change Pin
Judah Gabriel Himango1-Jul-05 5:25
sponsorJudah Gabriel Himango1-Jul-05 5:25 
Firstly, how is your example different from the implemented generics in 2.0? I can write the same class as

class Pair<T> : IComparable where T: IComparable
{
    T first;
    T second;

    public int CompareTo(T other)
    {
        ...
    }
}


Maybe I'm failing to see your point.

As far as why .NET generics are different from C++ templates, it's because with C++, all template instantiations are known at compile time! With a .NET assembly, your dll or exe could be loaded by someone else and could try to make invalid instantiations of your generic class after compile time.

Take for instance the following class:

class MyGenericDotNetClass<T>
{
    void FooBar(T foo)
    {
        foo.Yippie(); // How does .NET know that this .Yippie() method even exists?
    }
}


This would work as a C++ template, provided that any code that instanciates this class will provide a generic parameter type that has a .Bar() method. With a C++ template, if you said new MyGenericDotNetClass<sometypewithyippiemethod>(), then this would work because the C++ compiler would verify that the .Yippie() method exists for type SomeTypeWithYippieMethod.

.NET, on the other hand, can't depend solely on compile-time checking. Sure, the compiler could check to see if all your code that instantiates this class does so with a type that has a .Yippie() method. However, .NET code is easily shareable between components; a Visual Basic.NET application my load up your MyGenericDotNetClass and with a generic parameter of SomeTypeWithNoYippieMethod(). Of course, the VB.NET compiler could issue an error message, however, we'd then start getting into long, cryptic error message akin to C++ template compiler erros about bad instantiations because no .Yippie() method exists on the proposed generic type. Obviously, this is a quite simple example, real-world code would get much hairier than this. So the .NET designers decided that if you want functionality out of your generic class, you have to specify it explicitly in the form of a constraint.

Ian Griffiths has a good article on his blog here[^] about this very topic.

IMO, generics in .NET is pretty well done. I like it, it's useful, and saves a lot of development time. I think the only change I'd make is for the value types to have an arithmetic constraint of some sort, allowing generic types to easily add, subtract, multiple, divide, etc. But I hear there are plans for this in .NET version 3.

Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Conversation With a Muslim
Judah Himango


GeneralRe: Rational for Generics? Proposal for change Pin
Nick Hounsome1-Jul-05 9:26
Nick Hounsome1-Jul-05 9:26 
GeneralRe: Rational for Generics? Proposal for change Pin
Judah Gabriel Himango1-Jul-05 9:40
sponsorJudah Gabriel Himango1-Jul-05 9:40 
GeneralSOAPFormatter and &#229;&#228;&#246; Pin
Roger Alsing30-Jun-05 22:36
Roger Alsing30-Jun-05 22:36 
Generalexecute external program from a C# program Pin
StrayGrey30-Jun-05 22:23
StrayGrey30-Jun-05 22:23 
GeneralRe: execute external program from a C# program Pin
Weiye Chen30-Jun-05 22:47
Weiye Chen30-Jun-05 22:47 
GeneralRe: execute external program from a C# program Pin
StrayGrey30-Jun-05 22:49
StrayGrey30-Jun-05 22:49 
GeneralRe: execute external program from a C# program Pin
Weiye Chen30-Jun-05 23:02
Weiye Chen30-Jun-05 23:02 
GeneralRe: execute external program from a C# program Pin
StrayGrey4-Jul-05 20:56
StrayGrey4-Jul-05 20:56 
QuestionHow to get WSDL using WSE 2.0 Pin
iffi raja30-Jun-05 22:16
sussiffi raja30-Jun-05 22:16 
QuestionHow to change default Image of Cursor? Pin
pubududilena30-Jun-05 22:13
pubududilena30-Jun-05 22:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.