Newsgroups: microsoft.public.dotnet.languages.csharp
From: Ruediger Klaehn <kla...@gamemakers.de>
Date: Tue, 27 Jul 2004 14:47:18 +0200
Local: Tues, Jul 27 2004 8:47 am
Subject: Generics in .NET 2.0 SUCK
Sorry about the harsh language, but I have to vent my anger to somebody who
actually understands what I am talking about. Complaining to my girlfriend is not going to produce any meaningful results other than straining our relationship... I just downloaded Visual C# Express Edition to mess with .NET 2.0 generics. Imagine my surprise when I found out that what I want is basically This was my first try (this is only an excerpt): struct complex<T> } Something like this would work in C++, since it does not have constraints on type parameters. But in .NET, when you specify a type parameter without constraints it is assumed to be a System.Object, which of course does not have a + operator. So I thought, probably there is a way to specify a method constraint for T My second thought was that there might be some interface like IArithmetic. interface IArithmetic<T> { } should do the trick. This would not be very elegant, but quite sufficient. Given that there is an interface called IComparable<T> this should not be too much to ask. Maybe there should even be something more granular like interface IAddable<T> { } ... interface } or something. This solution would be similar to the approach taken with IComparable and IComparable<T>. But no such interface exists in the System namespace. So I would have to struct ArithmeticInt : IArithmetic<int> { } struct ArithmeticDouble : IArithmetic<double> { private double value; ... } But this would be a lot of work and, even worse, would lead to absymal performance since in my experience the .NET JIT compiler is too dumb to get rid of the wrapper code. There are of course some workarounds like having a separate type parameter struct Complex<T,Ops> where Ops:IArithmeticOps<T> } But this yields inacceptable performance. What is really required is a way to specify *method* *constraints* instead Another option would be to allow static methods in interfaces and to provide Without something like this, generics are only good for typed collections. You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||