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!
==== Built-in compound data types ==== Both languages treat [[String (computer science)|strings]] as ([[immutable object|immutable]]) objects of reference type. In both languages, the type contains several methods to manipulate strings, parse, format, etc. In both languages [[regular expression]]s are considered an external feature and are implemented in separate classes. Both languages' libraries define classes for working with dates, times, [[time zone]]s, and [[calendar]]s in different cultures. Java provides {{code|java.util.Date}}, a mutable reference type with millisecond precision, and (since Java 8) the {{code|java.time}} package (including classes such as {{mono|LocalDate}}, {{mono|LocalTime}}, and {{mono|LocalDateTime}} for date-only, time-only, and date-and-time values), a set of immutable reference types with [[nanosecond]] precision.<ref>{{cite web |url=https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html |title=Package java.time (Java Platform SE 8) |publisher=docs.oracle.com |access-date=20 April 2023}}</ref> In contrast, the C# {{code|System.DateTime}} is an immutable struct value type for date-and-time information with 100-nanosecond precision; the .NET 6 API also added {{code|System.DateOnly}} and {{code|System.TimeOnly}}, similar structures for date-only or time-only operations.<ref>{{cite web |url=https://learn.microsoft.com/en-us/dotnet/standard/datetime/how-to-use-dateonly-timeonly |title=How to use the DateOnly and TimeOnly structures |date=12 January 2023 |publisher=learn.microsoft.com |access-date=20 April 2023}}</ref> C# additionally defines a {{code|System.TimeSpan}} type for working with time periods; Java 8 provides the {{code|java.time.Duration}} class for the same purpose. Both languages support date and time arithmetic according to different cultures and time zones.
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)