-
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
Const ValueTuple #1034
Comments
Because there's no primitive representation of the ValueTuple types in the CLR. Also, the ValueTuple types are mutable, so that's a whole other can of worms. |
@drozdekl There are at least three issues with this:
So the following would work:
But the following isn't possible:
|
@eyalsk Thank you for your answer. I thought that it would be great to have const tuples but I understand that it is not possible. I thought that all necessary things would be known at compile time. If one wrote I almost forgot that ValueTuples are not built in and I shoudn't expect anything special about them. |
@drozdekl You welcome. :) |
I would like to ask another question but do not want to start a thread. Why can't ValueTuples consist only from one value? I have written buffered reader which knows key value from last reading and would like to make return value from writer in the same way. Currently I have: public interface IReaderStream<T> : IDisposable {
(T Item, object LastKey) Read(object key);
}
interface IWriterStream<T> : IDisposable {
object Write(T item, object key);
}
public interface IReader<T> {
T ReadFrom(IReaderStream<T> source);
}
interface IWriter<T> {
T WriteTo(IReaderStream<T> destination);
} But I would like to write |
@drozdekl You can check #883. :) |
Is there any possibility in language to have an interface which is publicly sealed? I would like to have such interface which would provide an interface to user and could be anytime completely replaced. Also I would like to make sure that I control which classes can implement that interface to influence correct behaviour. public static class Provider {
public IItem New() => new ItemImplementation();
}
// publicly sealed
public internal IItem {
}
internal class ItemImplementation() {
} User of that dll could write: IItem x = Provider.Build(); but not class A : IItem {
} |
@drozdekl There is an old proposal to do that: dotnet/roslyn#220. It's not clear to me why it was closed. There's also another similar (but broader) proposal at #485. But I don't think you should ask questions not related to your original issue here. You should either open a new issue or move to some other place, like the gitter channel (@eyalsk seems to be present there). |
Why can't ValueTuple's be declared const? I understand why value types generally can't be declared const but the reason about constructor can't be aplied to ValueTuples.
I tried to use
const (int, int) tuple = (1, 2);
in my code but it's not allowed.The text was updated successfully, but these errors were encountered: