Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Comparison of C Sharp and Java
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Tuples === C# provides two different methods for creating [[tuple]] types (also known as [[product type]]s). The first is via the {{code|System.Tuple}} classes, which are immutable reference types provided by the framework API (starting with .NET Framework 4.0) for creating generic tuple types.<ref name="C# Tuple class"/> This first method has since been effectively superseded by the second, the {{code|System.ValueTuple}} structs, which are mutable value types provided by the framework API (starting with .NET Framework 4.7).<ref name="C# value tuples"/> While the two methods seem superficially similar, they have multiple notable differences. The {{mono|ValueTuple}} types are value types, so they have a more compact memory footprint; also, the {{mono|ValueTuple}} types expose their contents as mutable fields, compared to the immutable properties of the {{mono|Tuple}} classes. Finally, since C# version 7.0, the language has native syntactical support for the construction, deconstruction, and manipulation of tuples as {{mono|ValueTuple}} instances; this also provides for the arbitrary renaming of the tuples' constituent fields (as opposed to {{mono|Tuple}}, where the fields are always named {{mono|Item1}}, {{mono|Item2}}, etc.). Java does not provide tuple types as part of its language or standard API; numerous third-party libraries exist which can provide tuple types,<ref>{{Cite web |url=https://www.javatuples.org/ |title=javatuples |access-date=20 April 2023}}</ref> but they all are necessarily similar to the C# {{code|System.Tuple}} classes. In comparison to C# {{mono|ValueTuple}} types and their associated syntax, they are more unwieldy to use (requiring the explicit use of constructors or static factory methods for creating them, requiring individual member access to deconstruct them, and having fixed names for their elements).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)