Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic types should support operators #2147

Closed
ygc369 opened this issue Apr 21, 2015 · 2 comments
Closed

Generic types should support operators #2147

ygc369 opened this issue Apr 21, 2015 · 2 comments

Comments

@ygc369
Copy link

ygc369 commented Apr 21, 2015

Generic constraints should be more exact, thus we would be able to use operators on generic types.
for example:
public static T Function1(T a,T b) where T:int,long,uint,ulong
{return a/b+a%b;}

@HaloFour
Copy link

C# is limited by the support for generic constraints offered by the CLR which only really supports class, struct, new(), a subclass and/or a list of interfaces.

Supporting operators would be tricky because operators are both applied to the built-in primitive types, such as the ones you listed, as well as through static methods on any custom type. The IL generated for + could not be the same for System.Int32 v. System.Decimal, but it would have to be.

I want to say that this request is duped (probably multiple times) but I'm having trouble finding an issue number. Perhaps it's still over on CodePlex.

@gafter
Copy link
Member

gafter commented Mar 20, 2017

We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages.

The use case for this would be addressed by concepts: dotnet/csharplang#110

@gafter gafter closed this as completed Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants