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

C# 3.0: no additions to where clause? dang.

I was hoping for increased functionality with the where clause in C#
3.0. Using the new keyword 'var' would really allow us to take nice
advantage of these. Specifically:

1. I want to limit it to primitives: "where T : System.Type.Primitive"
or something like that.
2. I want to limit it to an unspecified generic: "where T : List<>".
3. I want to limit it to a generic with a subset of types: "where T :
List<new TTwhere TT : class" or something similar.
4. I want to limit to a class with a certain property or method: "where
T : interface MyFunc(int), interface operator+=(int), interface get
MyProperty(int)" or something similar.
5. I want a default type: "where T default(MyType): IMyType" or
something similar so that I don't have to specify the type in all
situations. If it leads to ambiguous functions, throw an error.
6. Specify a namespace: "where T in System : class" or something like
that.
7. I want to AND/OR the conditions for the where clause together.

Thoughts? Comments? Complaints?

Jan 11 '07 #1
1 2749

"not_a_commie" <no********@gmail.comwrote in message
news:11*********************@i56g2000hsf.googlegro ups.com...
>I was hoping for increased functionality with the where clause in C#
3.0. Using the new keyword 'var' would really allow us to take nice
advantage of these. Specifically:

1. I want to limit it to primitives: "where T : System.Type.Primitive"
or something like that.
"where T : primitive" would be very nice, I agree
2. I want to limit it to an unspecified generic: "where T : List<>".
Just make S the generic parameter, you can use List<Sthroughout your
generic class
3. I want to limit it to a generic with a subset of types: "where T :
List<new TTwhere TT : class" or something similar.
Same as #2
4. I want to limit to a class with a certain property or method: "where
T : interface MyFunc(int), interface operator+=(int), interface get
MyProperty(int)" or something similar.
Since generics are shared between all reference types, this would only be
possible for type parameters restricted to value types. In that case it
would be extremely useful and perfect for generic arithmetic.

Would have to be syntax like:
where T : value having operator+=(T,T=>T)
5. I want a default type: "where T default(MyType): IMyType" or
something similar so that I don't have to specify the type in all
situations. If it leads to ambiguous functions, throw an error.
C# in general doesn't have default arguments but uses overloaded functions
to get the same user experience.

Generics can be overloaded based on the number of type arguments. So you
get what you're looking for with
public class Hashmap<T: Hashmap<string, T>
6. Specify a namespace: "where T in System : class" or something like
that.
7. I want to AND/OR the conditions for the where clause together.
The constraints are always and'ed, because if the compiler generates calls
in MSIL, the methods have to be available.

What would be useful would be constraint overloading:

class StableSortedList<T{ /* use a stable sort */ }
class SortedList<T{ /* use the fastest sort */ }
class StableSortedList<T: SortedList<T>
where T : ITotalOrdering, T : IUnique { /* if elements can never compare
equal, then needn't use the expensive stable sort algorithm */ }

The problem I see with that is that while the compiler could pick that
easily, it would tend not to propagate through other generics :(
>
Thoughts? Comments? Complaints?

Jan 11 '07 #2

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

Similar topics

16
by: middletree | last post by:
I have no idea what's going on. The more I use Access, the more I hate it. But for this church project, I have to use it. (I'm used to SQL Server) It was working fine, adding and inserting and...
3
by: A.V.C. | last post by:
Hello, I found members of this group very helpful for my last queries. Have one problem with CASE. I can use the column name alias in Order By Clause but unable to use it in WHERE CLAUSE. PLS...
29
by: C A Upsdell | last post by:
Comments re these three related, proposed CSS 3 additions? 1. Add 'text-transform:time', which would transform text in the format hours:minutes:seconds (24 hour clock) to the local format for...
6
by: Cro | last post by:
Dear Access Developers, The 'Allow Additions' property of my form is causing unexpected results. I am developing a form that has its 'Default View' property set to 'Continuous Forms' and am...
5
by: Mr. SweatyFinger | last post by:
Hi my checkbox list works great, except when i go to edit the items in the browser. It doesn't save the changes. This routine is supposed to save the newly checked items, instead it saves out...
2
by: Jim.Mueksch | last post by:
I am having a problem with using calculated values in a WHERE clause. My query is below. DB2 gives me this error message: Error: SQL0206N "APPRAISAL_LESS_PRICE" is not valid in the context where...
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
5
by: pwiegers | last post by:
Hi, I'm trying to use the result of a conditional statement in a where clause, but i'm getting 1)nowhere 2) desperate :-) The query is simple: -------- SELECT idUser,...
20
by: billmaclean1 | last post by:
I need to write a stored procedure that selects from a table and returns the result set. I don't always know the TableSchema that I need to use when qualifying the table at run-time Example:...
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: 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
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?
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...
0
marktang
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.