-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Yet another params proposal: params IReadOnlyList<T> #1366
Comments
the full list of generic array interfaces is as follow,
I think we should support all these as part of #179 we could also add void M(params int[] p)
void M(params IList<int> p)
void M(params ICollection<int> p)
void M(params IEnumerable<int> p)
void M(params IReadOnlyList<int> p)
void M(params IReadOnlyCollection<int> p)
void M(params Span<int> p)
M(1); // which method should be called? |
Other interfaces already are subject of other proposals. |
@alfredmyers Unless you are proposing that we do something contrary to what #179 proposes, what's the point of starting a new discussion? |
void M(params int[] p)
void M(params IList<int> p)
void M(params ICollection<int> p)
void M(params IEnumerable<int> p)
void M(params IReadOnlyList<int> p)
void M(params IReadOnlyCollection<int> p)
void M(params Span<int> p)
M(1); // which method should be called? If all these |
I like it, except that removing |
@portal-chan Then we have to figure out how this is handled: interface IA
{
void M(params ICollection<int> p);
}
interface IB
{
void M(params IReadOnlyCollection<int> p);
}
class C : IA, IB
{
// Must implement both
public void M(params ICollection<int> p) {}
public void M(params IReadOnlyCollection<int> p) {}
} |
@bondsbw I don't think that particular case would be an issue. While you can specify interface IA
{
void M(params int[] p);
}
class C : IA
{
public void M(int[] p) {}
} |
@svick TIL |
Default values don't have to match or even be present, either. |
For example, we could resolve void M(params int[] p)
void M(params Span<int> p) and choose the first one below for void M(params IEnumerable<int> p)
void M(params IReadOnlyList<long> p) But give declaration-site errors for these: void M(params int[] p)
void M(params IEnumerable<int> p) EDIT: as folks at gitter mentioned, it would not be necessary to define a precedence, since simply moving |
There are several proposals for allowing params to be used with types other than T[]: #178, #179, etc.
This proposal is specifically for
IReadOnlyList<T>
since T[] implicitly implements bothIList<T>
andIReadOnlyList<T>
So given a method
Both the following call sites would be valid:
The text was updated successfully, but these errors were encountered: