diff --git a/docs/csharp/index.yml b/docs/csharp/index.yml index 78df22d44e8d8..23fd2c6ac952a 100644 --- a/docs/csharp/index.yml +++ b/docs/csharp/index.yml @@ -14,7 +14,7 @@ metadata: ms.topic: hub-page author: billwagner ms.author: wiwagn - ms.date: 05/30/2025 + ms.date: 02/06/2026 # highlightedContent section (Optional; Remove if not applicable.) # Maximum of 8 items @@ -59,12 +59,12 @@ productDirectory: links: - url: ./tour-of-csharp/overview.md text: A tour of C# + - url: ./tour-of-csharp/what-you-can-build.md + text: What you can build with C# - url: ./tour-of-csharp/tutorials/index.md text: Beginner C# tutorials - - url: ./tour-of-csharp/tutorials/hello-world.md - text: Try C# in your browser - - url: ./fundamentals/program-structure/index.md - text: "Inside a C# program" + - url: ./tour-of-csharp/tips-for-java-developers.md + text: "C# for Java, JavaScript, and Python developers" - url: https://aka.ms/dotnet/beginnervideos/learn/csharp text: "C# for beginners video series" - url: https://aka.ms/csharp-certification diff --git a/docs/csharp/toc.yml b/docs/csharp/toc.yml index 5324dd7a241eb..f9d0623fd231d 100644 --- a/docs/csharp/toc.yml +++ b/docs/csharp/toc.yml @@ -5,6 +5,8 @@ items: items: - name: Tour of C# href: tour-of-csharp/overview.md + - name: What you can build + href: tour-of-csharp/what-you-can-build.md - name: Tutorials items: - name: Choose your first lesson diff --git a/docs/csharp/tour-of-csharp/index.yml b/docs/csharp/tour-of-csharp/index.yml index 56fc662e834fa..5c4587f1ea413 100644 --- a/docs/csharp/tour-of-csharp/index.yml +++ b/docs/csharp/tour-of-csharp/index.yml @@ -7,38 +7,36 @@ metadata: title: "C# docs - get started, tutorials, reference." description: "Learn C# programming - for beginning developers, developers new to C#, and experienced C# / .NET developers" ms.topic: landing-page # Required - ms.date: 05/29/2025 + ms.date: 02/06/2026 landingContent: - - title: "Learn to program" + - title: "Choose your path" linkLists: - linkListType: get-started links: - - text: Learn C# | Tutorials, courses, videos, and more - url: https://dotnet.microsoft.com/learn/csharp - - text: Beginner C# tutorials in your browser + - text: "New to programming? Start with beginner tutorials" url: ./tutorials/index.md - - linkListType: video - links: + - text: "In-browser tutorial: Hello world" + url: ./tutorials/hello-world.md - text: "C# beginner video series" url: https://aka.ms/dotnet/beginnervideos/youtube/csharp - - linkListType: tutorial + - linkListType: overview links: - - text: "Self-guided tutorials" - url: https://learn.microsoft.com/users/dotnet/collections/yz26f8y64n7k07?WT.mc_id=dotnet-35129-website - - text: "In-browser tutorial" - url: ./tutorials/hello-world.md - - linkListType: reference + - text: "Experienced developer? A tour of C#" + url: ./overview.md + - text: Learn C# for Java developers + url: ./tips-for-java-developers.md + - text: Learn C# for JavaScript developers + url: ./tips-for-javascript-developers.md + - text: Learn C# for Python developers + url: ./tips-for-python-developers.md + - linkListType: learn links: - - text: "C# on Q&A" - url: /answers/topics/dotnet-csharp.html - - text: "Languages on .NET tech community forums" - url: https://techcommunity.microsoft.com/t5/languages/bd-p/languages - - text: "C# on Stack Overflow" - url: https://stackoverflow.com/questions/tagged/c%23 - - text: "C# on Discord" - url: https://aka.ms/csharp-discord + - text: Foundational C# Certification + url: https://aka.ms/csharp-certification + - text: What you can build with C# + url: ./what-you-can-build.md - title: "Fundamentals" linkLists: @@ -50,7 +48,7 @@ landingContent: url: ../fundamentals/program-structure/index.md - text: "C# highlights video series" url: https://youtube.com/playlist?list=PLdo4fOcmZ0oU3ZLx6Ul1_HPrr6lFPIn9O - - text: C# Language development strategy + - text: C# language strategy url: ./strategy.md - linkListType: concept links: @@ -66,8 +64,8 @@ landingContent: url: ../fundamentals/coding-style/identifier-names.md - linkListType: tutorial links: - - text: Display command-line - url: ../fundamentals/tutorials/how-to-display-command-line-arguments.md + - text: Build file-based apps + url: ../fundamentals/tutorials/file-based-programs.md - text: Intro to classes url: ../fundamentals/tutorials/classes.md - text: Object oriented C# @@ -106,6 +104,8 @@ landingContent: linkLists: - linkListType: overview links: + - text: What you can build with C# + url: ./what-you-can-build.md - text: C# language strategy url: ./strategy.md - text: "Programming concepts" @@ -125,21 +125,6 @@ landingContent: - text: Learn C# for Python developers url: ./tips-for-python-developers.md - - title: "Advanced concepts" - linkLists: - - linkListType: reference - links: - - text: "Reflection and attributes" - url: ../advanced-topics/reflection-and-attributes/index.md - - text: "Expression trees" - url: ../advanced-topics/expression-trees/index.md - - text: "Native interoperability" - url: ../advanced-topics/interop/index.md - - text: "Performance engineering" - url: ../advanced-topics/performance/index.md - - text: ".NET Compiler Platform SDK" - url: ../roslyn-sdk/index.md - - title: "C# language reference" linkLists: - linkListType: reference @@ -152,25 +137,18 @@ landingContent: url: ../language-reference/operators/index.md - text: "Tokens" url: ../language-reference/tokens/index.md - - - title: "C# language standard" - linkLists: - - linkListType: reference - links: - - text: "Overview" - url: ../specification/overview.md - - text: "C# language specification" - url: ../../../_csharpstandard/standard/README.md - - text: "Feature specifications" - url: ../specification/feature-spec-overview.md - title: "Stay in touch" linkLists: - linkListType: reference links: + - text: "C# on Q&A" + url: /answers/topics/dotnet-csharp.html - text: ".NET developer community" url: https://dotnet.microsoft.com/platform/community + - text: "C# on Stack Overflow" + url: https://stackoverflow.com/questions/tagged/c%23 + - text: "C# on Discord" + url: https://aka.ms/csharp-discord - text: "YouTube" url: https://www.youtube.com/dotnet - - text: "Twitter" - url: https://twitter.com/DotNet diff --git a/docs/csharp/tour-of-csharp/overview.md b/docs/csharp/tour-of-csharp/overview.md index 8f386f0d28cf2..68878695d3b73 100644 --- a/docs/csharp/tour-of-csharp/overview.md +++ b/docs/csharp/tour-of-csharp/overview.md @@ -1,38 +1,45 @@ --- title: Overview description: New to C#? Learn the basics of the language. Start with this overview. -ms.date: 06/20/2025 +ms.date: 02/06/2026 --- # A tour of the C# language -The C# language is the most popular language for the [.NET platform](../index.yml), a free, cross-platform, open source development environment. C# programs can run on many different devices, from Internet of Things (IoT) devices to the cloud and everywhere in between. You can write apps for phone, desktop, and laptop computers and servers. +This article gives you a high-level overview of the C# language and the .NET platform. Whether you're writing your first program or you're an experienced developer exploring C#, you'll find the key concepts and features here. + +> [!TIP] +> **New to programming?** Skim this article for the big picture, then start the [beginner tutorials](./tutorials/index.md) to write code hands-on. +> +> **Coming from Java, JavaScript, or Python?** Read the tips for [Java](./tips-for-java-developers.md), [JavaScript](./tips-for-javascript-developers.md), or [Python](./tips-for-python-developers.md) developers alongside this article. +> +> **Experienced developer new to .NET?** This article covers what makes C# distinctive. See [What you can build with C#](./what-you-can-build.md) to find the workload that fits your goals. + +The C# language is the most popular language for the [.NET platform](../index.yml), a free, cross-platform, open source development environment. C# programs can run on many different devices, from Internet of Things (IoT) devices to the cloud and everywhere in between. You can write apps for phone, desktop, and laptop computers and servers. See [What you can build with C#](./what-you-can-build.md) for an overview of application types. C# is a cross-platform general purpose language that makes developers productive while writing highly performant code. With millions of developers, C# is the most popular .NET language. C# has broad support in the ecosystem and all .NET [workloads](../../standard/glossary.md#workload). Based on object-oriented principles, it incorporates many features from other paradigms, not least functional programming. Low-level features support high-efficiency scenarios without writing unsafe code. Most of the .NET runtime and libraries are written in C#, and advances in C# often benefit all .NET developers. -C# is in the C family of languages. [C# syntax](../language-reference/keywords/index.md) is familiar if you used C, C++, JavaScript, TypeScript, or Java. Like C and C++, semi-colons (`;`) define the end of statements. C# identifiers are case-sensitive. C# has the same use of braces, `{` and `}`, control statements like `if`, `else` and `switch`, and looping constructs like `for`, and `while`. C# also has a `foreach` statement for any collection type. +C# is in the C family of languages. [C# syntax](../language-reference/keywords/index.md) is familiar if you used C, C++, JavaScript, TypeScript, or Java. Like C and C++, semicolons (`;`) define the end of statements. C# identifiers are case-sensitive. C# has the same use of braces, `{` and `}`, control statements like `if`, `else`, and `switch`, and looping constructs like `for` and `while`. C# also has a `foreach` statement for any collection type. ## Hello world -The "Hello, World" program is traditionally used to introduce a programming language. Here it is in C#: +The "Hello, World" program traditionally introduces a programming language. Here's the program in C#: ```csharp // This line prints "Hello, World" Console.WriteLine("Hello, World"); ``` -The line starting with `//` is a *single line comment*. C# single line comments start with `//` and continue to the end of the current line. C# also supports *multi-line comments*. Multi-line comments start with `/*` and end with `*/`. The `WriteLine` method of the `Console` class, which is in the `System` namespace, produces the output of the program. This class is provided by the standard class libraries, which, by default, are automatically referenced in every C# program. Another program form requires you to declare the containing class and method for the program's entry point. The compiler synthesizes these elements when you use top-level statements. +The line starting with `//` is a *single line comment*. C# single line comments start with `//` and continue to the end of the current line. C# also supports *multi-line comments*. Multi-line comments start with `/*` and end with `*/`. The `WriteLine` method of the `Console` class, which is in the `System` namespace, produces the output of the program. The standard class libraries provide this class, and every C# program automatically references these libraries by default. Another program form requires you to declare the containing class and method for the program's entry point. The compiler synthesizes these elements when you use top-level statements. This alternative format is still valid and contains many of the basic concepts in all C# programs. Many existing C# samples use the following equivalent format: :::code language="csharp" source="./snippets/shared/HelloWorld.cs"::: -The preceding "Hello, World" program starts with a `using` directive that references the `System` namespace. Namespaces provide a hierarchical means of organizing C# programs and libraries. Namespaces contain types and other namespaces—for example, the `System` namespace contains many types, such as the `Console` class referenced in the program, and many other namespaces, such as `IO` and `Collections`. A `using` directive that references a given namespace enables unqualified use of the types that are members of that namespace. Because of the `using` directive, the program can use `Console.WriteLine` as shorthand for `System.Console.WriteLine`. In the earlier example, that namespace was [implicitly](../language-reference/keywords/using-directive.md#the-global-modifier) included. +The preceding "Hello, World" program starts with a `using` directive that references the `System` namespace. Namespaces provide a hierarchical means of organizing C# programs and libraries. Namespaces contain types and other namespaces. For example, the `System` namespace contains many types, such as the `Console` class referenced in the program, and many other namespaces, such as `IO` and `Collections`. A `using` directive that references a given namespace enables unqualified use of the types that are members of that namespace. Because of the `using` directive, the program can use `Console.WriteLine` as shorthand for `System.Console.WriteLine`. In the earlier example, that namespace was [implicitly](../language-reference/keywords/using-directive.md#the-global-modifier) included. -The `Program` class declared by the "Hello, World" program has a single member, the method named `Main`. The `Main` method is declared with the `static` modifier. While instance methods can reference a particular enclosing object instance using the keyword `this`, static methods operate without reference to a particular object. By convention, when there are no top-level statements a static method named `Main` serves as the [entry point](../fundamentals/program-structure/main-command-line.md) of a C# program. The class containing the `Main` method is typically named `Program`. - -> [!TIP] -> The examples in this article give you a first look at C# code. Some samples might show elements of C# that you're not familiar with. When you're ready to learn C#, start with our [beginner tutorials](./tutorials/index.md), or dive into the links in each section. If you're experienced in [Java](./tips-for-java-developers.md), [JavaScript](./tips-for-javascript-developers.md), [TypeScript](./tips-for-javascript-developers.md), or [Python](./tips-for-python-developers.md), read our tips to help you find the information you need to quickly learn C#. +> [!NOTE] +> The preceding program declares the `Program` class with a single member: the method named `Main`. Many existing C# samples and tutorials use this format. By convention, when there are no top-level statements, a static method named `Main` serves as the [entry point](../fundamentals/program-structure/main-command-line.md) of a C# program. Both formats compile to the same code. You don't need to use this format—file-based apps and top-level statements are simpler ways to get started. ## File-based apps @@ -54,14 +61,17 @@ The source for these programs must be a single file, but otherwise all C# syntax C# is approachable for beginners yet offers advanced features for experienced developers writing specialized applications. You can be productive quickly. You can learn more specialized techniques as you need them for your applications. -C# apps benefit from the .NET Runtime's [automatic memory management](../../standard/automatic-memory-management.md). C# apps also use the extensive [runtime libraries](../../standard/runtime-libraries-overview.md) provided by the .NET SDK. Some components are platform independent, like file system libraries, data collections, and math libraries. Others are specific to a single workload, like the ASP.NET Core web libraries, or the .NET MAUI UI library. A rich Open Source ecosystem on [NuGet](https://nuget.org) augments the libraries that are part of the runtime. These libraries provide even more components you can use. +C# apps benefit from the .NET runtime's [automatic memory management](../../standard/automatic-memory-management.md). C# apps also use the extensive [runtime libraries](../../standard/runtime-libraries-overview.md) provided by the .NET SDK. Some components are platform independent, like file system libraries, data collections, and math libraries. Others are specific to a single [workload](./what-you-can-build.md), like the ASP.NET Core web libraries or the .NET MAUI UI library. A rich open source ecosystem on [NuGet](https://nuget.org) augments the libraries that are part of the runtime. These libraries provide even more components you can use. -C# is a *strongly typed* language. Every variable you declare has a type known at compile time. The compiler, or editing tools tell you if you're using that type incorrectly. You can fix those errors before you ever run your program. [Fundamental data types](../fundamentals/types/index.md) are built into the language and runtime: value types like `int`, `double`, `char`, reference types like `string`, arrays, and other collections. As you write your programs, you create your own types. Those types can be `struct` types for values, or `class` types that define object-oriented behavior. You can add the `record` modifier to either `struct` or `class` types so the compiler synthesizes code for equality comparisons. You can also create `interface` definitions, which define a contract, or a set of members, that a type implementing that interface must provide. You can also define generic types and methods. [Generics](../fundamentals/types/generics.md) use *type parameters* to provide a placeholder for an actual type when used. +C# is a *strongly typed* language. Every variable you declare has a type known at compile time. The compiler, or editing tools, tell you if you're using that type incorrectly. You can fix those errors before you ever run your program. [Fundamental data types](../fundamentals/types/index.md) are built into the language and runtime: value types like `int`, `double`, `char`, reference types like `string`, arrays, and other collections. As you write your programs, you create your own types. Those types can be `struct` types for values, or `class` types that define object-oriented behavior. You can add the `record` modifier to either `struct` or `class` types so the compiler synthesizes code for equality comparisons. You can also create `interface` definitions, which define a contract, or a set of members, that a type implementing that interface must provide. You can also define generic types and methods. [Generics](../fundamentals/types/generics.md) use *type parameters* to provide a placeholder for an actual type when used. -As you write code, you define functions, also called [methods](../programming-guide/classes-and-structs/methods.md), as members of `struct` and `class` types. These methods define the behavior of your types. Methods can be overloaded, with different number or types of parameters. Methods can optionally return a value. In addition to methods, C# types can have [properties](../programming-guide/classes-and-structs/properties.md), which are data elements backed by functions called *accessors*. C# types can define [events](../events-overview.md), which allow a type to notify subscribers of important actions. C# supports object oriented techniques such as inheritance and polymorphism for `class` types. +As you write code, you define functions, also called [methods](../programming-guide/classes-and-structs/methods.md), as members of `struct` and `class` types. These methods define the behavior of your types. You can overload methods with different numbers or types of parameters. Methods can optionally return a value. In addition to methods, C# types can have [properties](../programming-guide/classes-and-structs/properties.md), which are data elements backed by functions called *accessors*. C# types can define [events](../events-overview.md), which allow a type to notify subscribers of important actions. C# supports object oriented techniques such as inheritance and polymorphism for `class` types. C# apps use [exceptions](../fundamentals/exceptions/index.md) to report and handle errors. This practice is familiar if you used C++ or Java. Your code throws an exception when it can't do what was intended. Other code, no matter how many levels up the call stack, can optionally recover by using a `try` - `catch` block. +> [!TIP] +> To learn more about types, methods, and exceptions, visit the [C# fundamentals](../fundamentals/program-structure/index.md) section. It covers the [type system](../fundamentals/types/index.md), [object-oriented programming](../fundamentals/object-oriented/index.md), and [exception handling](../fundamentals/exceptions/index.md) in depth. + ## Distinctive C# features Some elements of C# might be less familiar. @@ -70,7 +80,7 @@ C# provides [pattern matching](../fundamentals/functional/pattern-matching.md). :::code language="csharp" source="./snippets/shared/PatternMatching.cs" id="PatternExamples"::: -Pattern matching expressions can be simplified using `_` as a catch all for any value. The following example shows how you can simplify the *and* method: +Pattern matching expressions can be simplified by using `_` as a catchall for any value. The following example shows how you can simplify the *and* method: :::code language="csharp" source="./snippets/shared/PatternMatching.cs" id="ReducedPattern"::: @@ -80,7 +90,7 @@ The preceding examples also declare *tuples*, lightweight data structures. A *tu :::code language="csharp" source="./snippets/shared/CollectionExpressions.cs" id="CollectionExpressions"::: -The previous example shows different collection types that can be initialized using collection expressions. One example uses the `[]` empty collection expression to declare an empty collection. Another example uses the `..` *spread element* to expand a collection and add all its values to the collection expression. +The previous example shows different collection types that you can initialize by using collection expressions. One example uses the `[]` empty collection expression to declare an empty collection. Another example uses the `..` *spread element* to expand a collection and add all its values to the collection expression. You can use *index* and *range* expressions to retrieve one or more elements from an indexable collection: @@ -104,8 +114,21 @@ C# also supports an `await foreach` statement to iterate a collection backed by :::code language="csharp" source="./snippets/shared/AsyncSamples.cs" id="ReadDataAsync"::: -Callers can iterate the collection using an `await foreach` statement: +Callers can iterate the collection by using an `await foreach` statement: :::code language="csharp" source="./snippets/shared/AsyncSamples.cs" id="UseReadSequence"::: Finally, as part of the .NET ecosystem, you can use [Visual Studio](https://visualstudio.microsoft.com/vs), or [Visual Studio Code](https://code.visualstudio.com) with the [C# DevKit](https://code.visualstudio.com/docs/csharp/get-started). These tools provide rich understanding of C#, including the code you write. They also provide debugging capabilities. + +> [!TIP] +> To learn more about pattern matching, LINQ, and async programming, see the [functional techniques](../fundamentals/functional/pattern-matching.md), [LINQ overview](../linq/index.md), and [asynchronous programming](../asynchronous-programming/index.md) sections. + +## Next steps + +This article gave you a quick tour of the C# language. Here's where to go next, depending on your experience: + +- **Start coding**: Work through the [beginner tutorials](./tutorials/index.md) to learn C# step by step. +- **Go deeper**: Visit the [C# fundamentals](../fundamentals/program-structure/index.md) section for detailed coverage of the type system, object-oriented programming, and error handling. +- **Build something**: Explore [what you can build with C#](./what-you-can-build.md) to find ideas that interest you. +- **Coming from another language?** Read the guides for [Java](./tips-for-java-developers.md), [JavaScript](./tips-for-javascript-developers.md), or [Python](./tips-for-python-developers.md) developers. +- **Build file-based apps**: Learn how to [build file-based apps](../fundamentals/tutorials/file-based-programs.md) for small programs and prototypes. diff --git a/docs/csharp/tour-of-csharp/strategy.md b/docs/csharp/tour-of-csharp/strategy.md index 70113c2d4ba49..b458895a8937b 100644 --- a/docs/csharp/tour-of-csharp/strategy.md +++ b/docs/csharp/tour-of-csharp/strategy.md @@ -1,11 +1,14 @@ --- title: Language strategy description: We keep evolving C# to meet the changing needs of developers and remain a state-of-the-art programming language. We will innovate eagerly and broadly in collaboration with C# developers -ms.date: 03/17/2025 +ms.date: 02/06/2026 ms.update-cycle: 1825-days --- # Annotated C# strategy +> [!TIP] +> This article is most useful for professionals and students who want to understand C#'s design philosophy and how the language evolves. If you're new to C#, start with [A tour of C#](./overview.md) or the [beginner tutorials](./tutorials/index.md) instead. + [!INCLUDE [csharp](../../../includes/csharp-strategy.md)] ## How strategy guides C\# @@ -22,7 +25,7 @@ We evaluate new ideas in the spirit and history of the C# language. We prioritiz > "improvements that benefit all or most developers" -Developers use C# in all .NET workloads. Developers build web front and back ends, cloud native apps, and desktop apps with C#. C# enables cross platform applications. We focus on new features that have the most impact either directly, or by empowering improvements to common libraries. Language feature development includes integration into our developer tools and learning resources. +Developers use C# in all .NET [workloads](./what-you-can-build.md). Developers build web front and back ends, cloud native apps, and desktop apps with C#. C# enables cross platform applications. We focus on new features that have the most impact either directly, or by empowering improvements to common libraries. Language feature development includes integration into our developer tools and learning resources. > "high commitment to backwards compatibility" diff --git a/docs/csharp/tour-of-csharp/tips-for-java-developers.md b/docs/csharp/tour-of-csharp/tips-for-java-developers.md index 089e13fd9ecf8..e208890d8c835 100644 --- a/docs/csharp/tour-of-csharp/tips-for-java-developers.md +++ b/docs/csharp/tour-of-csharp/tips-for-java-developers.md @@ -1,13 +1,15 @@ --- title: Tips for Java Developers description: Are you new to C#, but experienced in Java? Here's a roadmap of what's familiar, and new features to learn in C#, and features in Java that aren't in C#. -ms.date: 04/17/2025 +ms.date: 02/09/2026 --- # Roadmap for Java developers learning C\# +If you're starting a new job or joining a team that uses C#, this article helps you get productive quickly. It highlights what's familiar from Java and what's new in C#. + C# and Java have many similarities. As you learn C#, you can apply much of the knowledge you already have from programming in Java: -1. ***Similar syntax***: Both Java and C# are in the C family of languages. That similarity means you can already read and understand C#. There are some differences, but most of the syntax is the same as Java, and C. The curly braces and semicolons are familiar. The control statements like `if`, `else`, `switch` are the same. The looping statements of `for`, `while`, and `do`...`while` are same. The same keywords for `class` and `interface` are in both languages. The access modifiers from `public` to `private` are the same. Even many of the builtin types use the same keywords: `int`, `string`, and `double`. +1. ***Similar syntax***: Both Java and C# are in the C family of languages. That similarity means you can already read and understand C#. There are some differences, but most of the syntax is the same as Java, and C. The curly braces and semicolons are familiar. The control statements like `if`, `else`, `switch` are the same. The looping statements of `for`, `while`, and `do`...`while` are same. The same keywords for `class` and `interface` are in both languages. The access modifiers from `public` to `private` are the same. Even many of the built-in types use the same keywords: `int`, `string`, and `double`. 1. ***Object-oriented paradigm***: Both Java and C# are object-oriented languages. The concepts of polymorphism, abstraction, and encapsulation apply in both languages. Both added new constructs, but the core features are still relevant. 1. ***Strongly typed***: Both Java and C# are strongly typed languages. You declare the data type of variables, either explicitly or implicitly. The compiler enforces type safety. The compiler catches type-related errors in your code, before you run the code. 1. ***Cross-platform***: Both Java and C# are cross-platform. You can run your development tools on your favorite platform. Your application can run on multiple platforms. Your development platform isn't required to match your target platform. @@ -15,7 +17,69 @@ C# and Java have many similarities. As you learn C#, you can apply much of the k 1. ***Standard libraries***: The .NET runtime and the Java Standard Library (JSL) have support for common tasks. Both have extensive ecosystems for other open source packages. In C#, the package manager is [NuGet](https://www.nuget.org). It's analogous to Maven. 1. ***Garbage Collection***: Both languages employ automatic memory management through garbage collection. The runtime reclaims the memory from objects that aren't referenced. One difference is that C# enables you to create value types, as `struct` types. -You can work productively in C# almost immediately because of the similarities. As you progress, you should learn features and idioms in C# that aren't available in Java: +## Syntax at a glance + +The following examples show a few common patterns side by side. These comparisons aren't exhaustive, but they give you a quick feel for the syntax differences. + +**Variable declaration and type inference:** + +```java +// Java +var name = "Hello"; +final int count = 5; +``` + +```csharp +// C# +var name = "Hello"; +const int count = 5; +``` + +**String interpolation:** + +```java +// Java +var message = "Hello, " + name + "! Count: " + count; +``` + +```csharp +// C# +var message = $"Hello, {name}! Count: {count}"; +``` + +Learn more: [String interpolation](../language-reference/tokens/interpolated.md) + +**Lambda expressions:** + +```java +// Java +list.stream().filter(x -> x > 5).collect(Collectors.toList()); +``` + +```csharp +// C# +var result = list.Where(x => x > 5).ToList(); +``` + +Learn more: [LINQ overview](../linq/index.md) + +**Null handling:** + +```java +// Java +String value = optional.orElse("default"); +``` + +```csharp +// C# +string value = input ?? "default"; +``` + +Learn more: [Nullable reference types](../nullable-references.md) + +## What's familiar + +You can work productively in C# almost immediately because of the similarities. As you progress, learn features and idioms in C# that aren't available in Java: 1. [***Pattern matching***](../fundamentals/functional/pattern-matching.md): Pattern matching enables concise conditional statements and expressions based on the shape of complex data structures. The [`is` statement](../language-reference/operators/is.md) checks if a variable "is" some pattern. The pattern-based [`switch` expression](../language-reference/operators/switch-expression.md) provides a rich syntax to inspect a variable and make decisions based on its characteristics. 1. [***String interpolation***](../language-reference/tokens/interpolated.md) and [***raw string literals***](../language-reference/builtin-types/reference-types.md#string-literals): String interpolation enables you to insert evaluated expressions in a string, rather than using positional identifiers. Raw string literals provide a way to minimize escape sequences in text. @@ -24,7 +88,10 @@ You can work productively in C# almost immediately because of the similarities. 1. [***LINQ***](../linq/index.md): Language integrated query (LINQ) provides a common syntax to query and transform data, regardless of its storage. 1. [***Local functions***](../programming-guide/classes-and-structs/local-functions.md): In C#, you can nest functions inside methods, or other local functions. Local functions provide yet another layer of encapsulation. -There are other features in C# that aren't in Java. Features like [`async` and `await`](../asynchronous-programming/index.md) model asynchronous operations in sequential syntax. The [`using`](../language-reference/statements/using.md) statement automatically free nonmemory resources. +> [!TIP] +> To learn more about C#'s type system—including `struct` vs. `class`, records, and interfaces—visit the [Type system](../fundamentals/types/index.md) overview in the Fundamentals section. + +There are other features in C# that aren't in Java. Features like [`async` and `await`](../asynchronous-programming/index.md) model asynchronous operations in sequential syntax. The [`using`](../language-reference/statements/using.md) statement automatically frees nonmemory resources. There are also some similar features between C# and Java that have subtle but important differences: @@ -39,3 +106,10 @@ Finally, there are Java language features that aren't available in C#: 1. ***Checked array covariance***: In C#, arrays aren't safely covariant. You should use the generic collection classes and interfaces if you need covariant structures. Overall, learning C# for a developer experienced in Java should be smooth. C# has enough familiar idioms for you to be productive as you learn the new idioms. + +## Next steps + +- [A tour of C#](./overview.md): Get a high-level overview of all C# features. +- [Beginner tutorials](./tutorials/index.md): Learn C# step by step with interactive lessons. +- [What you can build with C#](./what-you-can-build.md): Explore the application types you can create with C# and .NET. +- [C# fundamentals](../fundamentals/program-structure/index.md): Dive deeper into the type system, object-oriented programming, and more. diff --git a/docs/csharp/tour-of-csharp/tips-for-javascript-developers.md b/docs/csharp/tour-of-csharp/tips-for-javascript-developers.md index 129162df8c1c0..81350610a039c 100644 --- a/docs/csharp/tour-of-csharp/tips-for-javascript-developers.md +++ b/docs/csharp/tour-of-csharp/tips-for-javascript-developers.md @@ -1,34 +1,109 @@ --- title: Tips for JavaScript and TypeScript Developers description: "New to C#, but know JavaScript or TypeScript? Here's a roadmap of what's familiar, features in C# that aren't in JavaScript or TypeScript, and alternatives for features you use that aren't in C#" -ms.date: 03/17/2025 +ms.date: 02/06/2026 --- # Roadmap for JavaScript and TypeScript developers learning C\# -C#, TypeScript and JavaScript are all members of the C family of languages. The similarities between the languages help you quickly become productive in C#. +If you're joining a team that uses C#, or exploring .NET for server-side or full-stack development, this article helps you get productive quickly. It highlights what's familiar from JavaScript and TypeScript and what's new in C#. -1. ***Similar syntax***: JavaScript, TypeScript, and C# are in the C family of languages. That similarity means you can already read and understand C#. There are some differences, but most of the syntax is the same as JavaScript, and C. The curly braces and semicolons are familiar. The control statements like `if`, `else`, `switch` are the same. The looping statements of `for`, `while`, and `do`...`while` are same. The same keywords for `class` and `interface` are in both C# and TypeScript. The access modifiers in TypeScript and C#, from `public` to `private`, are the same. -1. ***The `=>` token***: All languages support lightweight function definitions. In C#, they're referred to as [*lambda expressions*](../language-reference/operators/lambda-expressions.md), in JavaScript, they're typically called *arrow functions*. +C#, TypeScript, and JavaScript are all members of the C family of languages. The similarities between the languages help you quickly become productive in C#. + +1. ***Similar syntax***: JavaScript, TypeScript, and C# are in the C family of languages. That similarity means you can already read and understand C#. There are some differences, but most of the syntax is the same as JavaScript and C. The curly braces and semicolons are familiar. The control statements like `if`, `else`, and `switch` are the same. The looping statements of `for`, `while`, and `do...while` are the same. The same keywords for `class` and `interface` are in both C# and TypeScript. The access modifiers in TypeScript and C#, from `public` to `private`, are the same. +1. ***The `=>` token***: All languages support lightweight function definitions. In C#, they're referred to as [*lambda expressions*](../language-reference/operators/lambda-expressions.md). In JavaScript, they're typically called *arrow functions*. 1. ***Function hierarchies***: All three languages support [local functions](../programming-guide/classes-and-structs/local-functions.md), which are functions defined in other functions. 1. ***Async / Await***: All three languages share the same `async` and `await` keywords for asynchronous programming. 1. ***Garbage collection***: All three languages rely on a garbage collector for automatic memory management. 1. ***Event model***: C#'s [`event`](../events-overview.md) syntax is similar to JavaScript's model for document object model (DOM) events. 1. ***Package manager***: [NuGet](https://nuget.org) is the most common package manager for C# and .NET, similar to npm for JavaScript applications. C# libraries are delivered in [assemblies](../../standard/assembly/index.md). -As you learn C#, you learn concepts that aren't part of JavaScript. Some of these concepts might be familiar to you if you use TypeScript: +## Syntax at a glance + +The following examples show a few common patterns side by side. These comparisons aren't exhaustive, but they give you a quick feel for the syntax differences. + +**Type annotations:** + +```typescript +// TypeScript +let name: string = "Hello"; +let count: number = 5; +``` + +```csharp +// C# +string name = "Hello"; +int count = 5; +``` + +**Async / await:** + +```typescript +// TypeScript +async function fetchData(): Promise { + const response = await fetch(url); + return await response.text(); +} +``` + +```csharp +// C# +async Task FetchDataAsync() { + var response = await client.GetAsync(url); + return await response.Content.ReadAsStringAsync(); +} +``` + +Learn more: [Asynchronous programming](../asynchronous-programming/index.md) + +**Classes:** + +```typescript +// TypeScript +class Point { + constructor(public x: number, public y: number) {} +} +``` + +```csharp +// C# +record Point(int X, int Y); +``` + +Learn more: [Records](../fundamentals/types/records.md) + +**Pattern matching:** + +```typescript +// TypeScript - manual type checking +if (typeof value === "string") { /* ... */ } +``` + +```csharp +// C# - pattern matching +if (value is string s) { /* use s */ } +``` + +Learn more: [Pattern matching](../fundamentals/functional/pattern-matching.md) + +## What's new for you in C\# + +As you learn C#, you encounter concepts that aren't part of JavaScript. Some of these concepts might be familiar to you if you use TypeScript: 1. [***C# Type System***](../fundamentals/types/index.md): C# is a strongly typed language. Every variable has a type, and that type can't change. You define `class` or `struct` types. You can define [`interface`](../fundamentals/types/interfaces.md) definitions that define behavior implemented by other types. TypeScript includes many of these concepts, but because TypeScript is built on JavaScript, the type system isn't as strict. 1. [***Pattern matching***](../fundamentals/functional/pattern-matching.md): Pattern matching enables concise conditional statements and expressions based on the shape of complex data structures. The [`is` expression](../language-reference/operators/is.md) checks if a variable "is" some pattern. The pattern-based [`switch` expression](../language-reference/operators/switch-expression.md) provides a rich syntax to inspect a variable and make decisions based on its characteristics. 1. [***String interpolation***](../language-reference/tokens/interpolated.md) and [***raw string literals***](../language-reference/builtin-types/reference-types.md#string-literals): String interpolation enables you to insert evaluated expressions in a string, rather than using positional identifiers. Raw string literals provide a way to minimize escape sequences in text. -1. [***Nullable and non-nullable types***](../nullable-references.md): C# supports *nullable value types*, and *nullable reference types* by appending the `?` suffix to a type. For nullable types, the compiler warns you if you don't check for `null` before dereferencing the expression. For non-nullable types, the compiler warns you if you might be assigning a `null` value to that variable. These features can minimize your application throwing a . The syntax might be familiar from TypeScript's use of `?` for optional properties. +1. [***Nullable and non-nullable types***](../nullable-references.md): C# supports *nullable value types* and *nullable reference types* by appending the `?` suffix to a type. For nullable types, the compiler warns you if you don't check for `null` before dereferencing the expression. For non-nullable types, the compiler warns you if you might be assigning a `null` value to that variable. These features can minimize your application throwing a . The syntax might be familiar from TypeScript's use of `?` for optional properties. 1. [***LINQ***](../linq/index.md): Language integrated query (LINQ) provides a common syntax to query and transform data, regardless of its storage. -As you learn more other differences become apparent, but many of those differences are smaller in scope. +> [!TIP] +> To learn more about C#'s type system—including `class` vs. `struct`, generics, and interfaces—visit the [Type system](../fundamentals/types/index.md) overview in the Fundamentals section. + +As you learn more, other differences become apparent, but many of those differences are smaller in scope. Some familiar features and idioms from JavaScript and TypeScript aren't available in C#: 1. ***dynamic types***: C# uses static typing. A variable declaration includes the type, and that type can't change. There's a [`dynamic`](../language-reference/builtin-types/reference-types.md#the-dynamic-type) type in C# that provides runtime binding. -1. ***Prototypal inheritance***: C# inheritance is part of the type declaration. A C# `class` declaration states any base class. In JavaScript, you can set the `__proto__` property to set the base type on any instance. +1. ***Prototypal inheritance***: C# inheritance is part of the type declaration. A C# `class` declaration states any base class. In JavaScript, you set the `__proto__` property to set the base type on any instance. 1. ***Interpreted language***: C# code must be compiled before you run it. JavaScript code can be run directly in the browser. In addition, a few more TypeScript features aren't available in C#: @@ -37,4 +112,11 @@ In addition, a few more TypeScript features aren't available in C#: 1. ***Decorators***: C# doesn't have decorators. Some common decorators, such as `@sealed` are reserved keywords in C#. Other common decorators might have corresponding [Attributes](../language-reference/attributes/general.md). For other decorators, you can create your own attributes. 1. ***More forgiving syntax***: The C# compiler parses code more strictly than JavaScript requires. -If you're building a web application, you should consider using [Blazor](/aspnet/core/blazor/index) to build your application. Blazor is a full-stack web framework built for .NET and C#. Blazor components can run on the server, as .NET assemblies, or on the client using WebAssembly. Blazor supports interop with your favorite JavaScript or TypeScript libraries. +If you're building a web application, consider using [Blazor](/aspnet/core/blazor/index) to build your application. Blazor is a full-stack web framework built for .NET and C#. Blazor components can run on the server, as .NET assemblies, or on the client using WebAssembly. Blazor supports interop with your favorite JavaScript or TypeScript libraries. + +## Next steps + +- [A tour of C#](./overview.md): Get a high-level overview of all C# features. +- [Beginner tutorials](./tutorials/index.md): Learn C# step by step with interactive lessons. +- [What you can build with C#](./what-you-can-build.md): Explore the application types you can create with C# and .NET. +- [C# fundamentals](../fundamentals/program-structure/index.md): Dive deeper into the type system, object-oriented programming, and more. diff --git a/docs/csharp/tour-of-csharp/tips-for-python-developers.md b/docs/csharp/tour-of-csharp/tips-for-python-developers.md index e3f6bc031f874..92d8122f18168 100644 --- a/docs/csharp/tour-of-csharp/tips-for-python-developers.md +++ b/docs/csharp/tour-of-csharp/tips-for-python-developers.md @@ -1,10 +1,12 @@ --- title: Tips for Python Developers description: New to C#, but know Python? Here's a roadmap of what's familiar, features in C# that aren't in Python, and alternatives for Python features that aren't in C#. -ms.date: 03/17/2025 +ms.date: 02/06/2026 --- # Roadmap for Python developers learning C\# +If you're moving from Python to C# for a new role or project, this article helps you get productive quickly. It highlights what's familiar from Python and what's different in C#. + C# and Python share similar concepts. These familiar constructs help you learn C# when you already know Python. 1. ***Object oriented***: Both Python and C# are object-oriented languages. All the concepts around classes in Python apply in C#, even if the syntax is different. @@ -15,7 +17,74 @@ C# and Python share similar concepts. These familiar constructs help you learn C 1. ***Pattern matching***: Python's `match` expression and pattern matching is similar to C#'s [pattern matching](../fundamentals/functional/pattern-matching.md) `switch` expression. You use them to inspect a complex data expression to determine if it matches a pattern. 1. ***Statement keywords***: Python and C# share many keywords, such as `if`, `else`, `while`, `for`, and many others. While not all syntax is the same, there's enough similarity that you can read C# if you know Python. -As you learn C#, you discover these important concepts where C# is different than Python: +## Syntax at a glance + +The following examples show a few common patterns side by side. These comparisons aren't exhaustive, but they give you a quick feel for the syntax differences. + +**Type annotations:** + +```python +# Python +name: str = "Hello" +count: int = 5 +``` + +```csharp +// C# +string name = "Hello"; +int count = 5; +``` + +**List filtering (comprehension vs. LINQ):** + +```python +# Python +result = [x for x in items if x > 5] +``` + +```csharp +// C# +var result = items.Where(x => x > 5).ToList(); +``` + +Learn more: [LINQ overview](../linq/index.md) + +**Block scope (indentation vs. braces):** + +```python +# Python +if count > 0: + print("positive") +``` + +```csharp +// C# +if (count > 0) +{ + Console.WriteLine("positive"); +} +``` + +**Class definition:** + +```python +# Python +class Point: + def __init__(self, x: int, y: int): + self.x = x + self.y = y +``` + +```csharp +// C# +record Point(int X, int Y); +``` + +Learn more: [Records](../fundamentals/types/records.md) + +## Key differences + +As you learn C#, you discover these important concepts where C# is different from Python: 1. [***Indentation vs. tokens***](./tutorials/branches-and-loops.md): In Python, newlines and indentation are first-class syntactic elements. In C#, whitespace isn't significant. Tokens, like `;` separate statements, and other tokens `{` and `}` control block scope for `if` and other block statements. However, for readability, most coding styles (including the style used in these docs) use indentation to reinforce the block scopes declared by `{` and `}`. 1. [***Static typing***](../fundamentals/types/index.md): In C#, a variable declaration includes its type. Reassigning a variable to an object of a different type generates a compiler error. In Python, the type can change when reassigned. @@ -23,10 +92,20 @@ As you learn C#, you discover these important concepts where C# is different tha 1. [***LINQ***](../linq/index.md): The query expression keywords that make up Language Integrated Query (LINQ) aren't keywords in Python. However, Python libraries like `itertools`, `more-itertools`, and `py-linq` provide similar functionality. 1. [***Generics***](../fundamentals/types/generics.md): C# generics use C# static typing to make assertions about the arguments supplied for type parameters. A generic algorithm might need to specify constraints that an argument type must satisfy. -Finally, there are some features of Python that aren't available in C#: +> [!TIP] +> To learn more about C#'s type system—including `class` vs. `struct`, generics, and interfaces—visit the [Type system](../fundamentals/types/index.md) overview in the Fundamentals section. + +Finally, some features of Python aren't available in C#: 1. ***Structural (duck) typing***: In C#, types have names and declarations. Except for [tuples](../language-reference/builtin-types/value-tuples.md), types with the same structure aren't interchangeable. 1. ***REPL***: C# doesn't have a Read-Eval-Print Loop (REPL) to quickly prototype solutions. 1. ***Significant whitespace***: You need to correctly use braces `{` and `}` to note block scope. Learning C# if you know Python is a smooth journey. The languages have similar concepts and similar idioms to use. + +## Next steps + +- [A tour of C#](./overview.md): Get a high-level overview of all C# features. +- [Beginner tutorials](./tutorials/index.md): Learn C# step by step with interactive lessons. +- [What you can build with C#](./what-you-can-build.md): Explore the application types you can create with C# and .NET. +- [C# fundamentals](../fundamentals/program-structure/index.md): Dive deeper into the type system, object-oriented programming, and more. diff --git a/docs/csharp/tour-of-csharp/tutorials/branches-and-loops.md b/docs/csharp/tour-of-csharp/tutorials/branches-and-loops.md index c60267493b448..ec261735c7d7a 100644 --- a/docs/csharp/tour-of-csharp/tutorials/branches-and-loops.md +++ b/docs/csharp/tour-of-csharp/tutorials/branches-and-loops.md @@ -1,12 +1,15 @@ --- title: Branches and loops - Introductory tutorial description: In this tutorial about branches and loops, you write C# code to explore the language syntax that supports conditional branches and loops to execute statements repeatedly. You write C# code and see the results of compiling and running your code directly in the browser. -ms.date: 12/10/2025 +ms.date: 02/09/2026 --- # Tutorial: C# `if` statements and loops - conditional logic This tutorial teaches you how to write C# code that examines variables and changes the execution path based on those variables. You write C# code and see the results of compiling and running it. The tutorial contains a series of lessons that explore branching and looping constructs in C#. These lessons teach you the fundamentals of the C# language. +> [!TIP] +> **New to programming?** Work through every section in order. **Coming from another language?** The `if`/`else` and loop syntax looks familiar - focus on the [nested loops](#created-nested-loops) and the [challenge](#combine-branches-and-loops) to practice C#-specific patterns. + In this tutorial, you: > [!div class="checklist"] @@ -21,7 +24,7 @@ In this tutorial, you: You must have one of the following options: -- A GitHub account to use [GitHub Codespaces](https://github.com/codespaces). If you don't already have one, you can create a free account at [GitHub.com](https://github.com). +- A GitHub account to use [GitHub Codespaces](https://github.com/codespaces). If you don't already have one, create a free account at [GitHub.com](https://github.com). - A computer with the following tools installed: - The [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0). - [Visual Studio Code](https://code.visualstudio.com/download). @@ -63,7 +66,7 @@ This first sample shows the power of `if` and Boolean types. A *Boolean* is a va ## Make if and else work together -To execute different code in both the true and false branches, you create an `else` branch that executes when the condition is false. Try an `else` branch. +To execute different code in both the true and false branches, create an `else` branch that runs when the condition is false. Try an `else` branch. 1. Add the last two lines in the following code snippet (you should already have the first four): @@ -97,7 +100,7 @@ To execute different code in both the true and false branches, you create an `el 1. Modify the values of `a`, `b`, and `c` and switch between `&&` and `||` to explore. You gain more understanding of how the `&&` and `||` operators work. -1. You finished the first step. Before you start the next section, let's move the current code into a separate method. That makes it easier to start working with a new example. Put the existing code in a method called `ExploreIf()`. Call it from the top of your program. When you finished those changes, your code should look like the following code: +1. You finished the first step. Before you start the next section, move the current code into a separate method. That change makes it easier to start working with a new example. Put the existing code in a method called `ExploreIf()`. Call it from the top of your program. When you finish those changes, your code should look like the following code: :::code language="csharp" source="./snippets/BranchesAndLoops/branches-loops.cs" id="Refactor"::: @@ -107,12 +110,15 @@ To execute different code in both the true and false branches, you create an `el //ExploreIf(); ``` -The `//` starts a **comment** in C#. Comments are any text you want to keep in your source code but not execute as code. The compiler doesn't generate any executable code from comments. +The `//` starts a **comment** in C#. Comments are any text you want to keep in your source code but don't execute as code. The compiler doesn't generate any executable code from comments. ## Use loops to repeat operations Another important concept for creating larger programs is **loops**. Use loops to repeat statements that you want to execute more than once. +> [!TIP] +> **Learn more:** Read about [iteration statements](../../language-reference/statements/iteration-statements.md) and [selection statements](../../language-reference/statements/selection-statements.md) in the C# language reference. + 1. Add this code after the call to `ExploreIf`: :::code language="csharp" source="./snippets/BranchesAndLoops/branches-loops.cs" id="WhileLoop"::: @@ -122,7 +128,7 @@ Another important concept for creating larger programs is **loops**. Use loops t There's one other new operator in this example. The `++` after the `counter` variable is the **increment** operator. It adds 1 to the value of `counter` and stores that value in the `counter` variable. > [!IMPORTANT] - > Make sure that the `while` loop condition changes to false as you execute the code. Otherwise, you create an **infinite loop** where your program never ends. That behavior isn't demonstrated in this sample, because you have to force your program to quit by using **CTRL-C** or other means. + > Make sure that the `while` loop condition changes to false as you execute the code. Otherwise, you create an **infinite loop** where your program never ends. This sample doesn't demonstrate that behavior, because you have to force your program to quit by using **CTRL-C** or other means. The `while` loop tests the condition before executing the code following the `while`. @@ -159,7 +165,7 @@ There's one other looping statement that isn't covered in this tutorial: the `fo ## Created nested loops -You can nest a `while`, `do`, or `for` loop inside another loop to create a matrix by combining each item in the outer loop with each item in the inner loop. Let's build a set of alphanumeric pairs to represent rows and columns. +You can nest a `while`, `do`, or `for` loop inside another loop. By combining each item in the outer loop with each item in the inner loop, you create a matrix. Let's build a set of alphanumeric pairs to represent rows and columns. 1. Add the following `for` loop that generates the rows: @@ -194,16 +200,23 @@ Did you come up with something like this? -You completed the "branches and loops" tutorial. You can learn more about these concepts in these articles: - -- [Selection statements](../../language-reference/statements/selection-statements.md) -- [Iteration statements](../../language-reference/statements/iteration-statements.md) +You completed the "branches and loops" tutorial. ## Cleanup resources GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and navigate to [your Codespaces](https://github.com/codespaces). You should see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace and select **delete**. -## Next step +## Next steps + +Continue to the next tutorial in this series: > [!div class="nextstepaction"] > [Learn about collections](list-collection.md) + +Or explore related topics in C# Fundamentals: + +- [Pattern matching](../../fundamentals/functional/pattern-matching.md) — A powerful alternative to complex `if`/`else` chains. +- [Methods and program structure](../../fundamentals/program-structure/index.md) — Learn how to organize the methods you created in this tutorial. +- [What you can build with C#](../what-you-can-build.md) — See the kinds of apps you can create with what you're learning. +- [Selection statements](../../language-reference/statements/selection-statements.md) +- [Iteration statements](../../language-reference/statements/iteration-statements.md) diff --git a/docs/csharp/tour-of-csharp/tutorials/hello-world.md b/docs/csharp/tour-of-csharp/tutorials/hello-world.md index 12e5bbd87bf9c..408ee1686c92e 100644 --- a/docs/csharp/tour-of-csharp/tutorials/hello-world.md +++ b/docs/csharp/tour-of-csharp/tutorials/hello-world.md @@ -1,13 +1,16 @@ --- title: Hello World - Introductory tutorial description: In this tutorial, you create your first C# apps. You write C# code and learn basic structure and types in C#. -ms.date: 12/10/2025 +ms.date: 02/06/2026 # customer intent: As an aspiring developer, I want to learn C#. --- # Tutorial: Explore the C# language This tutorial teaches you C#. You write your first C# program and see the results of compiling and running your code. It contains a series of lessons that begin with a "Hello World" program. These lessons teach you the fundamentals of the C# language. +> [!TIP] +> **New to programming?** Start here - this tutorial assumes no prior experience. **Coming from another language?** You might prefer to skim the code samples and jump ahead to [Numbers in C#](numbers-in-csharp.md) or [Branches and loops](branches-and-loops.md). + In this tutorial, you: > [!div class="checklist"] @@ -113,10 +116,13 @@ You're not limited to a single variable between the curly braces. You've been using a *method*, , to print messages. A *method* is a block of code that implements some action. It has a name, so you can access it. +> [!TIP] +> **Learn more:** Explore [strings](../../programming-guide/strings/index.md) in depth, or read about [methods and program structure](../../fundamentals/program-structure/index.md) in the C# Fundamentals section. + ## Remove whitespace from strings Suppose your strings have leading or trailing spaces that you don't want to display. You want to **trim** the spaces from the strings. -The method and related methods and do that work. You can use those methods to remove leading and trailing spaces. +The method and related methods and perform this task. Use these methods to remove leading and trailing spaces. 1. Try the following code: @@ -146,7 +152,7 @@ You can use other methods to work with a string. For example, you might use a se :::code language="csharp" source="./snippets/HelloWorld/hello-world.cs" id="SearchStrings"::: - The method returns a *boolean* value which tells you if the string you were searching for was found. A *boolean* stores either a `true` or a `false` value. When displayed as text output, they're capitalized: `True` and `False`, respectively. You learn more about *boolean* values in a later lesson. + The method returns a *boolean* value that tells you if the string you were searching for was found. A *boolean* stores either a `true` or a `false` value. When displayed as text output, they're capitalized: `True` and `False`, respectively. You learn more about *boolean* values in a later lesson. ## Challenge @@ -176,7 +182,13 @@ For further reading on the `string` type: GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and navigate to [your Codespaces](https://github.com/codespaces). You should see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace and select "delete". -## Next step +## Next steps + +Continue to the next tutorial in this series, or explore related topics in C# Fundamentals: > [!div class="nextstepaction"] > [Explore numbers in C#](numbers-in-csharp.md) + +- [Strings](../../programming-guide/strings/index.md) — Learn more about the `string` type you used in this tutorial. +- [Methods and program structure](../../fundamentals/program-structure/index.md) — Understand how C# programs are organized. +- [File-based programs](../../fundamentals/tutorials/file-based-programs.md) — Learn about the `dotnet run` command you used to run your code. diff --git a/docs/csharp/tour-of-csharp/tutorials/index.md b/docs/csharp/tour-of-csharp/tutorials/index.md index 2027537667400..8743391cbc40a 100644 --- a/docs/csharp/tour-of-csharp/tutorials/index.md +++ b/docs/csharp/tour-of-csharp/tutorials/index.md @@ -1,11 +1,18 @@ --- title: Interactive tutorials description: Learn C# using GitHub Codespaces, and get started with your own development environment. -ms.date: 12/10/2025 +ms.date: 02/09/2026 --- # Introduction to C\# -Welcome to the introduction to C# tutorials. These lessons start with interactive code that you can run in GitHub codespaces. You can learn the basics of C# from the [C# for Beginners video series](https://aka.ms/dotnet/beginnervideos/youtube/csharp) before starting these interactive lessons. +Welcome to the introduction to C# tutorials. These lessons start with interactive code that you can run in GitHub Codespaces. You can learn the basics of C# from the [C# for Beginners video series](https://aka.ms/dotnet/beginnervideos/youtube/csharp) before starting these interactive lessons. + +> [!TIP] +> **New to programming?** Start with tutorial 1 ([Hello world](hello-world.md)) and work through each lesson in order. +> +> **Coming from another language?** You can skim tutorials 1–2 and start with [Tuples and types](tuples-and-types.md) for concepts that might be new. + +All tutorials use file-based apps. You can use our [GitHub Codespace](https://github.com/dotnet/tutorial-codespace), or install the [.NET SDK](../../../core/install/index.yml), and you're ready to start. > [!VIDEO https://www.youtube.com/embed/9THmGiSPjBQ?si=3kUKFtOMLpEzeq7J] @@ -37,3 +44,12 @@ The [List collection](list-collection.md) lesson gives you a tour of the List co ## Pattern matching The [Pattern matching](pattern-matching.md) lesson provides an introduction to *pattern matching*. Pattern matching enables you to compare an expression against a pattern. The success of the match determines which program logic to follow. Patterns can compare types, properties of a type, or contents of a list. You can combine multiple patterns by using `and`, `or`, and `not` logic. Patterns provide a rich vocabulary to inspect data and make decisions in your program based on that inspection. + +## What's next? + +After you finish these tutorials, continue your learning journey: + +- [Build file-based apps](../../fundamentals/tutorials/file-based-programs.md): Learn how to create and run single-file C# programs from the command line. +- [What you can build with C#](../what-you-can-build.md): Explore the types of applications you can create with C# and .NET. +- [C# type system](../../fundamentals/types/index.md): Dive deeper into value types, reference types, generics, and more. +- [C# fundamentals](../../fundamentals/program-structure/index.md): Learn about program structure, object-oriented programming, and error handling. diff --git a/docs/csharp/tour-of-csharp/tutorials/list-collection.md b/docs/csharp/tour-of-csharp/tutorials/list-collection.md index ace6226b4a0a7..801f9787b980b 100644 --- a/docs/csharp/tour-of-csharp/tutorials/list-collection.md +++ b/docs/csharp/tour-of-csharp/tutorials/list-collection.md @@ -1,7 +1,7 @@ --- title: Data collections - Introductory tutorial description: In this tutorial, you use GitHub Codespaces to learn about C# collections. You write C# code and see the results of compiling and running your code in the Codespaces environment. -ms.date: 12/10/2025 +ms.date: 02/09/2026 --- # Tutorial: Learn to manage data collections using List\ in C\# @@ -9,6 +9,9 @@ This introductory tutorial provides an introduction to the C# language and the b This tutorial teaches you C#. You write C# code and see the results of compiling and running that code. It contains a series of lessons that create, modify, and explore collections. You work primarily with the class. +> [!TIP] +> **New to programming?** Work through each section in order. **Coming from another language?** If you already know dynamic arrays or lists, skim the basics and focus on [search and sort](#search-and-sort-lists), [lists of other types](#lists-of-other-types), and the [challenge](#challenge). + In this tutorial, you: > [!div class="checklist"] @@ -20,7 +23,7 @@ In this tutorial, you: ## Prerequisites -You must have one of the following: +You must have one of the following options: - A GitHub account to use [GitHub Codespaces](https://github.com/codespaces). If you don't already have one, you can create a free account at [GitHub.com](https://github.com). - A computer with the following tools installed: @@ -30,7 +33,7 @@ You must have one of the following: ## A basic list example -To start a GitHub Codespace with the tutorial environment, open a browser window to the [tutorial codespace](https://github.com/dotnet/tutorial-codespace) repository. Select the green *Code* button, and the *Codespaces* tab. Then select the `+` sign to create a new Codespace using this environment. If you completed other tutorials in this series, you can open that codespace instead of creating a new one. +To start a GitHub Codespace with the tutorial environment, open a browser window to the [tutorial codespace](https://github.com/dotnet/tutorial-codespace) repository. Select the green *Code* button, and select the *Codespaces* tab. Then select the `+` sign to create a new Codespace using this environment. If you completed other tutorials in this series, you can open that codespace instead of creating a new one. 1. When your codespace loads, create a new file in the *tutorials* folder named *lists.cs*. 1. Open your new file. @@ -55,7 +58,10 @@ Let's keep exploring. The collection you created uses the type. This type stores sequences of elements. You specify the type of the elements between the angle brackets. -One important aspect of this type is that it can grow or shrink, enabling you to add or remove elements. You can see the results by modifying the contents after you displayed its contents. +> [!TIP] +> **Learn more:** Explore [collections](../../../standard/collections/index.md) and [generics](../../fundamentals/types/generics.md) in the .NET documentation. + +One important aspect of this type is that it can grow or shrink, so you can add or remove elements. You can see the results by modifying the contents after you displayed its contents. 1. Add the following code after the code you already wrote (the loop that prints the contents): @@ -63,11 +69,11 @@ One important aspect of this type is You added two more names to the end of the list. You also removed one as well. The output from this block of code shows the initial contents, then prints a blank line and the new contents. -1. The enables you to reference individual items by **index** as well. You access items using the `[` and `]` tokens. Add the following code after what you already wrote and try it: +1. The type also enables you to reference individual items by **index**. You access items by using the `[` and `]` tokens. Add the following code after what you already wrote and try it: :::code language="csharp" source="./snippets/ListCollection/list.cs" id="Indexers"::: - You're not allowed to access past the end of the list. You can check how long the list is by using the property. + You can't access past the end of the list. You can check how long the list is by using the property. 1. Add the following code: @@ -79,15 +85,15 @@ For more information about indices, see the [Explore indexes and ranges](../../t ## Search and sort lists -Our samples use relatively small lists, but your applications might often create lists with many more elements, sometimes numbering in the thousands. To find elements in these larger collections, you need to search the list for different items. The method searches for an item and returns the index of the item. If the item isn't in the list, `IndexOf` returns `-1`. +The samples use relatively small lists, but your applications might often create lists with many more elements, sometimes numbering in the thousands. To find elements in these larger collections, you need to search the list for different items. The method searches for an item and returns the index of the item. If the item isn't in the list, `IndexOf` returns `-1`. 1. Try it to see how it works. Add the following code after what you wrote so far: :::code language="csharp" source="./snippets/ListCollection/list.cs" id="Search"::: - You might not know if an item is in the list, so you should always check the index returned by . If it's `-1`, the item wasn't found. + You might not know if an item is in the list, so always check the index returned by . If it's `-1`, the item wasn't found. -1. You can also sort the items in your list. The method sorts all the items in the list in their normal order (alphabetically for strings). Add this code and run again: +1. You can also sort the items in your list. The method sorts all the items in the list in their normal order (alphabetically for strings). Add this code and run it again: :::code language="csharp" source="./snippets/ListCollection/list.cs" id="Sort"::: @@ -99,7 +105,7 @@ So far, you've been using the `string` type in lists. Let's make a
@@ -122,17 +128,24 @@ With each iteration of the loop, you take the last two integers in the list, sum
-You completed the list tutorial. You can learn more about [.NET collections](../../../standard/collections/index.md) in the following articles: - -- [Selecting a collection type](../../../standard/collections/selecting-a-collection-class.md) -- [Commonly used collection types](../../../standard/collections/commonly-used-collection-types.md) -- [When to use generic collections](../../../standard/collections/when-to-use-generic-collections.md) +You completed the list tutorial. ## Cleanup resources GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and navigate to [your Codespaces](https://github.com/codespaces). You should see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace and select **delete**. -## Next step +## Next steps + +Continue to the next tutorial in this series: > [!div class="nextstepaction"] > [Pattern matching](pattern-matching.md) + +Or explore related topics in C# Fundamentals: + +- [Generics in C#](../../fundamentals/types/generics.md) — Understand the `` syntax you used throughout this tutorial. +- [LINQ overview](../../linq/index.md) — Query and transform collections by using Language Integrated Query. +- [What you can build with C#](../what-you-can-build.md) — See the kinds of apps you can create with what you're learning. +- [Selecting a collection type](../../../standard/collections/selecting-a-collection-class.md) +- [Commonly used collection types](../../../standard/collections/commonly-used-collection-types.md) +- [When to use generic collections](../../../standard/collections/when-to-use-generic-collections.md) diff --git a/docs/csharp/tour-of-csharp/tutorials/numbers-in-csharp.md b/docs/csharp/tour-of-csharp/tutorials/numbers-in-csharp.md index 3bd7e5db99a67..6fe2a20df0f99 100644 --- a/docs/csharp/tour-of-csharp/tutorials/numbers-in-csharp.md +++ b/docs/csharp/tour-of-csharp/tutorials/numbers-in-csharp.md @@ -1,12 +1,15 @@ --- title: Work with Numbers - Introductory tutorial description: This tutorial teaches you about the numeric types in C#. The tutorial contains a series of lessons that explore numbers and math operations in C#. -ms.date: 12/10/2025 +ms.date: 02/06/2026 --- # Tutorial: How to use integer and floating point numbers in C\# This tutorial teaches you about the numeric types in C#. You write small amounts of code, then you compile and run that code. The tutorial contains a series of lessons that explore numbers and math operations in C#. These lessons teach you the fundamentals of the C# language. +> [!TIP] +> **New to programming?** Work through each section in order. **Coming from another language?** You might already know integer vs. floating-point distinctions - skim the basics and focus on the [precision and limits](#explore-integer-precision-and-limits) and [decimal type](#work-with-decimal-types) sections. + In this tutorial, you: > [!div class="checklist"] @@ -20,7 +23,7 @@ In this tutorial, you: ## Prerequisites -You must have one of the following: +You must have one of the following options: - A GitHub account to use [GitHub Codespaces](https://github.com/codespaces). If you don't already have one, you can create a free account at [GitHub.com](https://github.com). - A computer with the following tools installed: @@ -62,7 +65,12 @@ You can also experiment by writing multiple mathematics operations in the same l > [!TIP] > As you explore C# (or any programming language), you might make mistakes when you write code. The **compiler** finds those errors and reports them to you. When the output contains error messages, look closely at the example code and the code in your window to see what to fix. You can also ask Copilot to find differences or spot mistakes. That exercise helps you learn the structure of C# code. -You finished the first step. Before you start the next section, let's move the current code into a separate *method*. A method is a series of statements grouped together and given a name. You call a method by writing the method's name followed by `()`. Organizing your code into methods makes it easier to start working with a new example. When you finish, your code should look like this: +You finished the first step. Before you start the next section, move the current code into a separate *method*. A method is a series of statements grouped together and given a name. You call a method by writing the method's name followed by `()`. Organizing your code into methods makes it easier to start working with a new example. + +> [!TIP] +> **Learn more:** Read about [methods and program structure](../../fundamentals/program-structure/index.md) in C# Fundamentals. + +When you finish, your code should look like this: ```csharp WorkWithIntegers(); @@ -91,21 +99,21 @@ void WorkWithIntegers() ## Explore order of operations -1. Comment out the call to `WorkingWithIntegers()`. It makes the output less cluttered as you work in this section: +1. Comment out the call to `WorkingWithIntegers()`. This change makes the output less cluttered as you work in this section: ```csharp //WorkWithIntegers(); ``` - The `//` starts a **comment** in C#. Comments are any text you want to keep in your source code but not execute as code. The compiler doesn't generate any executable code from comments. Because `WorkWithIntegers()` is a method, you need to only comment out one line. + The `//` starts a **comment** in C#. Comments are any text you want to keep in your source code but not execute as code. The compiler doesn't generate any executable code from comments. Because `WorkWithIntegers()` is a method, you need to comment out only one line. -1. The C# language defines the precedence of different mathematics operations with rules consistent with the rules you learned in mathematics. Multiplication and division take precedence over addition and subtraction. Explore that by adding the following code after the call to `WorkWithIntegers()`, and typing `dotnet numbers.cs` in the terminal window: +1. The C# language defines the precedence of different mathematics operations with rules consistent with the rules you learned in mathematics. Multiplication and division take precedence over addition and subtraction. Explore that precedence by adding the following code after the call to `WorkWithIntegers()`, and typing `dotnet numbers.cs` in the terminal window: :::code language="csharp" source="./snippets/NumbersInCsharp/numbers.cs" id="Precedence"::: The output demonstrates that the multiplication is performed before the addition. -1. You can force a different order of operation by adding parentheses around the operation or operations you want performed first. Add the following lines and run again: +1. You can force a different order of operation by adding parentheses around the operation or operations you want performed first. Add the following lines and run the app again: :::code language="csharp" source="./snippets/NumbersInCsharp/numbers.cs" id="Parentheses"::: @@ -121,7 +129,7 @@ void WorkWithIntegers() 1. Type `dotnet numbers.cs` again in the terminal window to see the results. -Before moving on, let's take all the code you wrote in this section and put it in a new method. Call that new method `OrderPrecedence`. Your code should look something like this: +Before moving on, take all the code you wrote in this section and put it in a new method. Call that new method `OrderPrecedence`. Your code should look something like this: ```csharp // WorkWithIntegers(); @@ -182,13 +190,13 @@ The previous sample showed that integer division truncates the result. You can g :::code language="csharp" source="./snippets/NumbersInCsharp/numbers.cs" id="MinAndMax"::: -1. If a calculation produces a value that exceeds those limits, you have an **underflow** or **overflow** condition. The answer appears to wrap from one limit to the other. To see an example, add these two lines to your code: +1. If a calculation produces a value that exceeds those limits, you get an **underflow** or **overflow** condition. The answer appears to wrap from one limit to the other. To see an example, add these two lines to your code: :::code language="csharp" source="./snippets/NumbersInCsharp/numbers.cs" id="Overflow"::: Notice that the answer is very close to the minimum (negative) integer. It's the same as `min + 2`. The addition operation **overflowed** the allowed values for integers. The answer is a large negative number because an overflow "wraps around" from the largest possible integer value to the smallest. -There are other numeric types with different limits and precision that you can use when the `int` type doesn't meet your needs. Let's explore those types of numbers next. +If the `int` type doesn't meet your needs, use other numeric types with different limits and precision. Let's explore those types of numbers next. ## Work with the double type @@ -256,17 +264,23 @@ You should get an answer between 19 and 20. Try some other formulas if you'd like. -You can learn more about numbers in C# in the following articles: - -- [Integral numeric types](../../language-reference/builtin-types/integral-numeric-types.md) -- [Floating-point numeric types](../../language-reference/builtin-types/floating-point-numeric-types.md) -- [Built-in numeric conversions](../../language-reference/builtin-types/numeric-conversions.md) - ## Cleanup resources GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and go to [your Codespaces](https://github.com/codespaces). You should see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace and select **delete**. -## Next step +## Next steps + +Continue with the next tutorial in this series: > [!div class="nextstepaction"] > [Tuples and types](tuples-and-types.md) + +Or explore related topics in C# Fundamentals: + +- [The C# type system](../../fundamentals/types/index.md) — Dive deeper into the types you used in this tutorial. +- [Methods and program structure](../../fundamentals/program-structure/index.md) — Learn more about the methods you created to organize your code. +- [What you can build with C#](../what-you-can-build.md) — See the kinds of apps you can create with what you're learning. +- [Numeric types in C# Fundamentals](../../fundamentals/types/index.md) — Understand how C# represents numbers in the type system. +- [Integral numeric types](../../language-reference/builtin-types/integral-numeric-types.md) +- [Floating-point numeric types](../../language-reference/builtin-types/floating-point-numeric-types.md) +- [Built-in numeric conversions](../../language-reference/builtin-types/numeric-conversions.md) diff --git a/docs/csharp/tour-of-csharp/tutorials/pattern-matching.md b/docs/csharp/tour-of-csharp/tutorials/pattern-matching.md index 9a80e509e5ff9..28c07ea158c79 100644 --- a/docs/csharp/tour-of-csharp/tutorials/pattern-matching.md +++ b/docs/csharp/tour-of-csharp/tutorials/pattern-matching.md @@ -1,12 +1,15 @@ --- title: Pattern matching description: In this tutorial about pattern matching, you learn C#. You're going to write C# code and see the results of compiling and running your code. -ms.date: 12/10/2025 +ms.date: 02/09/2026 --- # Tutorial: Use C# to match data against patterns This tutorial teaches you how to use pattern matching to inspect data in C#. You write small amounts of code, then you compile and run that code. The tutorial contains a series of lessons that explore different kinds of patterns supported by C#. These lessons teach you the fundamentals of the C# language. +> [!TIP] +> **New to programming?** Work through each section in order. **Coming from another language?** If you already know `switch` statements, focus on [exhaustive matches](#exhaustive-matches-with-switch) and [type patterns](#type-patterns) – these are distinctive C# features. + In this tutorial, you: > [!div class="checklist"] @@ -19,7 +22,7 @@ In this tutorial, you: ## Prerequisites -You must have one of the following: +You must have one of the following options: - A GitHub account to use [GitHub Codespaces](https://github.com/codespaces). If you don't already have one, you can create a free account at [GitHub.com](https://github.com). - A computer with the following tools installed: @@ -29,7 +32,7 @@ You must have one of the following: ## Match a value -The preceding tutorials demonstrated built-in types and types you define as tuples or records. You can check instances of these types against a *pattern*. Whether an instance matches a pattern determines the actions your program takes. In the examples below, you see `?` after type names. This symbol allows the value of this type to be null (for example, `bool?` can be `true`, `false`, or `null`). For more information, see [Nullable value types](../../language-reference/builtin-types/nullable-value-types.md). Let's start to explore how you can use patterns. +The preceding tutorials demonstrated built-in types and types you define as tuples or records. You can check instances of these types against a *pattern*. Whether an instance matches a pattern determines the actions your program takes. In the examples that follow, you see `?` after type names. This symbol allows the value of this type to be null (for example, `bool?` can be `true`, `false`, or `null`). For more information, see [Nullable value types](../../language-reference/builtin-types/nullable-value-types.md). Let's start to explore how you can use patterns. Open a browser window to [GitHub codespaces](https://github.com/codespaces). Create a new codespace from the *.NET Template*. If you completed other tutorials in this series, you can open that codespace. @@ -52,6 +55,9 @@ Open a browser window to [GitHub codespaces](https://github.com/codespaces). Cre You could similarly construct the preceding sample by using the `==` operator to test that two `string` values are equal. Comparing a variable to a constant is a basic building block for pattern matching. Let's explore more of the building blocks that are part of pattern matching. +> [!TIP] +> **Learn more:** Read about [pattern matching](../../fundamentals/functional/pattern-matching.md) in the C# Fundamentals section for a comprehensive overview of all pattern types. + ## Enum matches Another common use for pattern matching is matching on the values of an `enum` type. The following sample processes the input records to create a *tuple* where the first value is an `enum` value that notes a deposit or a withdrawal. The second value is the value of the transaction. @@ -106,14 +112,14 @@ The `else if` clause never matches because every number less than 10 is also les }; ``` - After you reorder the switch arms, type `dotnet patterns.cs` in the terminal window. The compiler issues an error because the arm with `_` matches every value. As a result, that final arm with `TransactionType.Withdrawal` never runs. The compiler tells you that something's wrong in your code. + After you reorder the switch arms, type `dotnet patterns.cs` in the terminal window. The compiler reports an error because the arm with `_` matches every value. As a result, that final arm with `TransactionType.Withdrawal` never runs. The compiler tells you that something's wrong in your code. - The compiler issues a warning if the expression tested in a `switch` expression could contain values that don't match any switch arm. If some values could fail to match any condition, the `switch` expression isn't *exhaustive*. The compiler also issues a warning if some values of the input don't match any of the switch arms. + The compiler reports a warning if the expression tested in a `switch` expression could contain values that don't match any switch arm. If some values can't match any condition, the `switch` expression isn't *exhaustive*. The compiler also reports a warning if some values of the input don't match any of the switch arms. 1. Remove the line with `_ => 0.0,`, so that any invalid values don't match. 1. Type `dotnet patterns.cs` to see the results. - The compiler issues a warning. The test data is valid, so the program works. However, any invalid data would cause a failure at runtime. + The compiler reports a warning. The test data is valid, so the program works. However, any invalid data would cause a failure at runtime. ## Type patterns @@ -138,14 +144,19 @@ Pattern matching provides a vocabulary to compare an expression against characte - [Pattern matching in C#](../../fundamentals/functional/pattern-matching.md) - [Explore pattern matching tutorial](../../tutorials/patterns-objects.md) - [Pattern matching scenario](../../fundamentals/tutorials/pattern-matching.md) +- [The C# type system](../../fundamentals/types/index.md) — Understand the types you matched against in this tutorial. ## Cleanup resources GitHub automatically deletes your Codespace after 30 days of inactivity. You completed all the tutorials in this series. To delete your Codespace now, open a browser window and go to [your Codespaces](https://github.com/codespaces). You should see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace and select **delete**. -## Related content +## Next steps + +You completed all the introductory tutorials! Here's where to go next: +- [File-based programs](../../fundamentals/tutorials/file-based-programs.md) — Learn about the `dotnet run` command you used throughout these tutorials. +- [C# Fundamentals](../../fundamentals/program-structure/index.md) — Dive deeper into program structure, types, and object-oriented programming. +- [What you can build with C#](../what-you-can-build.md) — See the kinds of apps you can create with what you learned. - Download and install the [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0). - Download and install [Visual Studio Code](https://code.visualstudio.com/download). - Download and install the [C# DevKit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit). -- Explore the [C# fundamentals section](../../fundamentals/program-structure/index.md) to learn more about C#. diff --git a/docs/csharp/tour-of-csharp/tutorials/tuples-and-types.md b/docs/csharp/tour-of-csharp/tutorials/tuples-and-types.md index 4ad28a7dcb075..a3c42b0c3811f 100644 --- a/docs/csharp/tour-of-csharp/tutorials/tuples-and-types.md +++ b/docs/csharp/tour-of-csharp/tutorials/tuples-and-types.md @@ -1,12 +1,15 @@ --- title: Tuples and types - Introductory tutorial description: This tutorial teaches you to create types in C#. You write C# code and see the results of compiling and running your code as you learn the structure of types. -ms.date: 12/10/2025 +ms.date: 02/06/2026 --- # Tutorial: Create types in C\# This tutorial teaches you how to create types in C#. You write small amounts of code, then you compile and run that code. The tutorial contains a series of lessons that explore different kinds of types in C#. These lessons teach you the fundamentals of the C# language. +> [!TIP] +> **New to programming?** Work through each section in order - tuples, records, and then structs and classes. **Coming from another language?** If you already know classes and structs, focus on [tuples](#tuples) and [record types](#create-record-types), which might be new to you. + The preceding tutorials worked with text and numbers. Strings and numbers are *simple types*: They each store one single value. As your programs grow larger, you need to work with more sophisticated data structures. C# provides different kinds of types you can define when you need data structures with more fields, properties, or behavior. Let's start to explore those types. In this tutorial, you: @@ -19,7 +22,7 @@ In this tutorial, you: ## Prerequisites -You must have one of the following: +You must have one of the following options: - A GitHub account to use [GitHub Codespaces](https://github.com/codespaces). If you don't already have one, you can create a free account at [GitHub.com](https://github.com). - A computer with the following tools installed: @@ -77,15 +80,18 @@ To start a GitHub Codespace with the tutorial environment, open a browser window While tuples are easy to create, they're limited in their capabilities. Tuple types don't have names, so you can't convey meaning to the set of values. Tuple types can't add behavior. C# has other kinds of types you can create when your type defines behavior. +> [!TIP] +> **Learn more:** Explore [tuples and other type choices](../../fundamentals/types/index.md) in C# Fundamentals. + ## Create record types -Tuples are great for those times when you want multiple values in the same structure. They're lightweight, and you can declare them as you use them. As your program grows, you might find that you use the same tuple type throughout your code. If your app works in the 2D graph space, the tuples that represent points might be common. When you find this pattern, you can declare a `record` type that stores those values and provides more capabilities. +Tuples work well when you want multiple values in the same structure. They're lightweight, and you can declare them as you use them. As your program grows, you might find that you use the same tuple type throughout your code. If your app works in the 2D graph space, the tuples that represent points might be common. When you find this pattern, declare a `record` type that stores those values and provides more capabilities. 1. Add the following code to declare and use a `record` type to represent a `Point`: :::code language="csharp" source="./snippets/TuplesAndTypes/tuples-types.cs" id="PointRecord"::: - The preceding code must be at the bottom of your source file. Type declarations like `record` declarations must follow executable statements in a file-based app. + Place the preceding code at the bottom of your source file. Type declarations like `record` declarations must follow executable statements in a file-based app. 1. Add the following code preceding the `record` declaration: @@ -119,7 +125,7 @@ Tuples are great for those times when you want multiple values in the same struc All concrete named types in C# are either `class` or `struct` types, including `record` types. A `class` is a *reference type*. A `struct` is a *value type*. Variables of a value type store the contents of the instance inline in memory. In other words, a `record struct Point` stores two integers: `X` and `Y`. Variables of a reference type store a reference, or pointer, to the storage for the instance. In other words, a `record class Point` stores a reference to a block of memory that holds the values for `X` and `Y`. -In practice, that means value types are copied when assigned, but a copy of a class instance is a copy of the *reference*. That copied reference refers to the same instance of a point, with the same storage for `X` and `Y`. +In practice, that difference means value types are copied when assigned, but a copy of a class instance is a copy of the *reference*. That copied reference refers to the same instance of a point, with the same storage for `X` and `Y`. The `record` modifier instructs the compiler to write several members for you. You can learn more in the article on [record types](../../fundamentals/types/records.md) in the fundamentals section. @@ -131,17 +137,22 @@ You can also define `interface` types to declare behavioral contracts that diffe You typically use all these types in larger programs and libraries. Once you install the .NET SDK, you can explore those types using tutorials on [classes](../../fundamentals/tutorials/classes.md) in the fundamentals section. -You completed the "Create types in C#" tutorial. You can learn more about types in C# in the following articles: - -- [Types in C#](../../fundamentals/types/index.md) -- [Records](../../fundamentals/types/records.md) -- [Classes](../../fundamentals/types/classes.md) +You completed the "Create types in C#" tutorial. ## Cleanup resources GitHub automatically deletes your Codespace after 30 days of inactivity. If you plan to explore more tutorials in this series, you can leave your Codespace provisioned. If you're ready to visit the [.NET site](https://dotnet.microsoft.com/download/dotnet) to download the .NET SDK, you can delete your Codespace. To delete your Codespace, open a browser window and navigate to [your Codespaces](https://github.com/codespaces). You should see a list of your codespaces in the window. Select the three dots (`...`) in the entry for the learn tutorial codespace and select **delete**. -## Next step +## Next steps + +Continue to the next tutorial in this series: > [!div class="nextstepaction"] > [Branches and loops](branches-and-loops.md) + +Or explore related topics in C# Fundamentals: + +- [The C# type system](../../fundamentals/types/index.md) — Dive deeper into the types you used in this tutorial. +- [Record types](../../fundamentals/types/records.md) — Learn more about records and when to use them. +- [Classes](../../fundamentals/types/classes.md) — Explore object-oriented programming in C#. +- [What you can build with C#](../what-you-can-build.md) — See the kinds of apps you can create with what you're learning. diff --git a/docs/csharp/tour-of-csharp/what-you-can-build.md b/docs/csharp/tour-of-csharp/what-you-can-build.md new file mode 100644 index 0000000000000..e3d504157c15c --- /dev/null +++ b/docs/csharp/tour-of-csharp/what-you-can-build.md @@ -0,0 +1,86 @@ +--- +title: What you can build with C# +description: Explore the types of applications you can build with C# and .NET, including web, desktop, mobile, cloud, IoT, AI, and games. +ms.date: 02/10/2026 +ai-usage: ai-assisted +--- + +# What you can build with C\# + +C# and the [.NET platform](../../standard/glossary.md#implementation-of-net) support a wide range of application types. Whatever kind of software you want to build, there's likely a .NET [workload](../../standard/glossary.md#workload) for it. This article gives you an overview of the most common types of applications, with links to get started on each one. + +> [!TIP] +> **New to programming?** Don't worry about choosing a workload yet. Focus on [learning the C# language](tutorials/index.md) first. You can explore these application types once you're comfortable with the basics. +> +> **Experienced developer?** Jump directly to the workload that matches your goals. Each section links to the documentation and tutorials you need. + +## AI and machine learning + +C# integrates with AI and machine learning tools: + +- **[ML.NET](../../machine-learning/index.yml)** - Build custom machine learning models in C# without requiring deep ML expertise. +- **[Semantic Kernel](/semantic-kernel/)** - Integrate large language models (LLMs) into your applications. +- **[Azure AI services](/azure/ai-services/)** - Access pre-built AI capabilities like vision, language understanding, and speech recognition. + +Get started with [ML.NET tutorials](../../machine-learning/index.yml). + +## Web applications + +Build web applications with [ASP.NET Core](/aspnet/core/), the cross-platform framework for creating modern web apps and APIs. You can build: + +- **Server-rendered web apps** using Razor Pages or MVC. +- **Interactive web UIs** using [Blazor](/aspnet/core/blazor/), which lets you write client-side logic in C# instead of JavaScript. +- **Web APIs** and [minimal APIs](/aspnet/core/fundamentals/minimal-apis/overview) for backend services. + +Get started: [ASP.NET Core tutorials](/aspnet/core/tutorials) + +## Desktop applications + +C# supports building desktop applications for Windows and macOS: + +- **[.NET MAUI](/dotnet/maui/)** creates cross-platform desktop apps that run on Windows, macOS, Android, and iOS from a single codebase. +- **[Windows Presentation Foundation (WPF)](/dotnet/desktop/wpf/)** builds rich Windows desktop apps with advanced graphics and data binding. +- **[Windows Forms](/dotnet/desktop/winforms/)** provides a straightforward way to create Windows desktop apps with a visual designer. + +Get started: [.NET MAUI tutorials](/dotnet/maui/get-started/first-app) + +## Mobile applications + +Build native mobile apps for iOS and Android by using [.NET MAUI](/dotnet/maui/). .NET MAUI lets you share code across mobile and desktop platforms while still accessing native device APIs for cameras, sensors, GPS, and more. + +Get started: [Build your first .NET MAUI app](/dotnet/maui/get-started/first-app) + +## Cloud and microservices + +C# and .NET are well suited for building cloud-native applications and microservices: + +- **[Azure SDK for .NET](../../azure/sdk/azure-sdk-for-dotnet.md)** provides libraries for working with Azure services like storage, messaging, and databases. +- **[Worker Services](../../core/extensions/workers.md)** let you build long-running background services that run in the cloud or on-premises. +- **[Aspire](https://aspire.dev)** streamlines building, running, deploying, debugging, and deploying distributed apps + +Get started: [Get started with Azure and .NET](../../azure/index.yml). + +## Games + +C# is one of the most popular languages for game development: + +- **[Unity](https://docs.unity3d.com/Manual/index.html)** - The most widely used game engine for 2D and 3D games, uses C# as its scripting language. +- **[MonoGame](https://docs.monogame.net/?page=main)** - An open-source framework for creating cross-platform games. +- **[CryEngine](https://docs.cryengine.com/display/CEPROG/C%23+Programming)** - Supports C# for game scripting. + +You can also use [Visual Studio for game development](https://visualstudio.microsoft.com/vs/features/game-development/?utm_medium=microsoft&utm_source=learn.microsoft.com&utm_campaign=inline+link) with these engines. + +## Internet of Things (IoT) + +Control devices and read sensor data by using the [.NET IoT libraries](../../iot/index.yml). You can run C# apps on devices like [Raspberry Pi](../../iot/quickstarts/sensehat.md) and other single-board computers to build IoT solutions. + +Get started: [.NET IoT tutorials](../../iot/tutorials/blink-led.md) + +## Next steps + +Now that you know what you can build, choose your next step: + +- **Learn the language**: Start with the [beginner C# tutorials](tutorials/index.md) to learn C# fundamentals. +- **Explore C#**: Read [A tour of C#](overview.md) for an overview of key language features. +- **Dive into fundamentals**: Visit the [C# fundamentals](../fundamentals/program-structure/index.md) section for deeper coverage of the type system, object-oriented programming, and more. +- **Coming from another language?** See the roadmaps for [Java](tips-for-java-developers.md), [JavaScript/TypeScript](tips-for-javascript-developers.md), or [Python](tips-for-python-developers.md) developers.