- Saved searches
- Use saved searches to filter your results more quickly
- License
- ahotko/c-sharp-code-examples
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- C# Tutorial
- Examples in Each Chapter
- Example
- C# Exercises
- Learn by Examples
- C# Quiz
- My Learning
- Kickstart your career
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
- Introduction to C#
- Hello world
- Numbers in C#
- Branches and loops
- List collection
- 101 Linq Samples
- Feedback
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
C# Code Examples / Snippets
License
ahotko/c-sharp-code-examples
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
C# Code Examples (mostly for myself)
A collection of code samples I have used C# and think they might be useful in the future.
- Abstract Class
- Anonymous Types
- Attributes and Conditionals
- Debugger
- DebuggerDisplay
- DebuggerBrowsable
- Conditional
- #if — #define — #endif
- Compiler Warning
- Compiler Error
- Get current Class name
- Get current Method Name
- Constructor Chaining
- Caller Info
- IEquatable Additional links: Link
- IEqualityComparer Additional links: Link
- Creational Patterns
- Singleton Pattern
- Factory Method Pattern
- Abstract Factory Pattern
- Strategy Pattern
- Observer Pattern
- State Pattern
- Dictionary Additional links: Link
- OrderedDictionary (requires System.Collections.Specialized ); Additional links: Link
- SortedDictionary Additional links: Link
- Sum
- Sum by Groups
- Ordering (asc, desc)
- Skipping
- Take N elements
- Select Samples with value between
- Single Responsibility Principle
- Inversion of Control
- Auto Property
- Auto Property with default value
- Property getter/setter
- String Interpolation
- Using
- Pattern Matching
- BackgroundWorker
- Thread
C# Tutorial
C# (C-Sharp) is a programming language developed by Microsoft that runs on the .NET Framework.
C# is used to develop web apps, desktop apps, mobile apps, games and much more.
Examples in Each Chapter
Our «Try it Yourself» editor makes it easy to learn C#. You can edit C# code and view the result in your browser.
Example
using System; namespace HelloWorld < class Program < static void Main(string[] args) < Console.WriteLine("Hello World!"); >> >
Click on the «Run example» button to see how it works.
We recommend reading this tutorial, in the sequence listed in the left menu.
C# Exercises
Learn by Examples
Learn by examples! This tutorial supplements all explanations with clarifying examples.
C# Quiz
Learn by taking a quiz! The quiz will give you a signal of how much you know, or do not know, about C#.
My Learning
Track your progress with the free «My Learning» program here at W3Schools.
Log in to your account, and start earning points!
This is an optional feature. You can study W3Schools without using My Learning.
Kickstart your career
Get certified by completing the course
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
Introduction to C#
Welcome to the introduction to C# tutorials. These lessons start with interactive code that you can run in your browser. You can learn the basics of C# from the C# 101 video series before starting these interactive lessons.
The first lessons explain C# concepts using small snippets of code. You’ll learn the basics of C# syntax and how to work with data types like strings, numbers, and booleans. It’s all interactive, and you’ll be writing and running code within minutes. These first lessons assume no prior knowledge of programming or the C# language.
You can try these tutorials in different environments. The concepts you’ll learn are the same. The difference is which experience you prefer:
- In your browser, on the docs platform: This experience embeds a runnable C# code window in docs pages. You write and execute C# code in the browser.
- In the Microsoft Learn training experience. This learning path contains several modules that teach the basics of C#.
- In Jupyter on Binder. You can experiment with C# code in a Jupyter notebook on binder.
- On your local machine. After you’ve explored online, you can download the .NET SDK and build programs on your machine.
All the introductory tutorials following the Hello World lesson are available using the online browser experience or in your own local development environment. At the end of each tutorial, you decide if you want to continue with the next lesson online or on your own machine. There are links to help you set up your environment and continue with the next tutorial on your machine.
Hello world
In the Hello world tutorial, you’ll create the most basic C# program. You’ll explore the string type and how to work with text. You can also use the path on Microsoft Learn training or Jupyter on Binder.
Numbers in C#
In the Numbers in C# tutorial, you’ll learn how computers store numbers and how to perform calculations with different numeric types. You’ll learn the basics of rounding, and how to perform mathematical calculations using C#. This tutorial is also available to run locally on your machine.
This tutorial assumes that you’ve finished the Hello world lesson.
Branches and loops
The Branches and loops tutorial teaches the basics of selecting different paths of code execution based on the values stored in variables. You’ll learn the basics of control flow, which is the basis of how programs make decisions and choose different actions. This tutorial is also available to run locally on your machine.
This tutorial assumes that you’ve finished the Hello world and Numbers in C# lessons.
List collection
The List collection lesson gives you a tour of the List collection type that stores sequences of data. You’ll learn how to add and remove items, search for items, and sort the lists. You’ll explore different kinds of lists. This tutorial is also available to run locally on your machine.
This tutorial assumes that you’ve finished the lessons listed above.
101 Linq Samples
This sample requires the dotnet-try global tool. Once you install the tool, and clone the try-samples repo, you can learn Language Integrated Query (LINQ) through a set of 101 samples you can run interactively. You can explore different ways to query, explore, and transform data sequences.
Feedback
Submit and view feedback for
- Debugger