Welcome to C# Examples. This site is focused on simple straightforward code examples suitable for copy and paste. You can subscribe to RSS feed .
Recent Examples
- 2016–05–15 – [C#] LINQ Aggregation Methods – Sum, Max, Min, Count, LongCount, Average, Aggregate
- 2016–03–15 – [C#] List – illustrative examples for all List<T> methods
- 2016–02–02 – [C#] Using Statement Examples – using statement and IDisposable
- 2016–01–30 – [C#] Switch Examples – switch statement examples
- 2016–01–11 – [C#] Foreach Examples – how foreach and IEnumerable works
- 2015–12–12 – [C#] Read Text File – how to read lines from text file
C# Interactive Examples
- [C#] Foreach Examples – how foreach and IEnumerable works debuggable online
- [C#] Switch Examples – switch statement examples debuggable online
- [C#] Using Statement Examples – using statement and IDisposable debuggable online
Fundamental .NET Classes
- [C#] List – illustrative examples of all List<T> methods
String Formatting
- [C#] String Format for DateTime – format date and time popular
- [C#] String Format for Double – format float numbers popular
- [C#] String Format for Int – format (align) integer numbers
- [C#] Align String with Spaces – how to align text to the right or left
- [C#] Indent String with Spaces – how to indent text with repeated spaces
- [C#] IFormatProvider for Numbers – parse float numbers with IFormatProvider
- [C#] Custom IFormatProvider – string formatting with custom IFormatProvider
- [C#] Culture Names – get all culture names in .NET Framework
Files and Folders
- [C#] FileStream Open File – how to open file using file stream popular
- [C#] FileStream Read File – how to safely read file stream
- [C#] Read Text File – how to read lines from text files
- [C#] Load Text File to String – how to load text from file to string
- [C#] Get Files from Directory – how to get files from directory popular
- [C#] Delete All Files – how to delete files from the specified directory
- [C#] Get Application Directory – how to get application or assembly folder
- [C#] File Attributes – how to get or set file attributes
- [C#] Get File Time – how to get last modification time of a file
- [C#] Open File With Associated Application – how to launch the default application
XML
- [C#] Select XML Nodes by Name – how to get xml nodes using XPath expressions popular
- [C#] Select XML Nodes by Attribute Value – how to get xml nodes by attribute value
- [C#] Select Top XML Nodes using XPath – how to select only first N xml nodes
Reflection
- [C#] Reflection Examples – examples how to use dynamically loaded assembly
- [C#] Get Method Names using Reflection – get names of methods of any class
- [C#] Get Property Names using Reflection – get property names of any class
- [C#] Get Calling Method using Reflection – how to get name of calling method
- [C#] Get Call Stack – how to write method names from call stack
- [C#] Read-only PropertyGrid – how to add read-only functionality to PropertyGrid
LINQ
- [C#] LINQ Aggregation Methods:
- LINQ Sum – gets sum of numeric collection
- LINQ Max – gets maximal item from collection
- LINQ Min – gets minimal item from collection
- LINQ Count – counts number of items in a collection (result type is Int32)
- LINQ LongCount – counts number of items in a collection (result type is Int64)
- LINQ Average – computes average value of numeric collection
- LINQ Aggregate – applies aggregate function to a collection
Network and Sockets
- [C#] Socket Send and Receive – how to send and receive TCP/IP data using sockets
- [C#] Download Files from Web – how to download files from url to local disk
- [C#] Check Local IP Address – check whether an IP is local
Threading
- [C#] Create an Asynchronous Method – how to invoke an asynchronous method
- [C#] Asynchronous Method Progress Reporting – how to report progress
- [C#] Cancel an Asynchronous Method – implement cancellation support
- [C#] Create New Thread – how to create thread in .NET
- [C#] Catching Unhandled Exceptions – how to catch unhandled thread exceptions
Windows Forms
- [C#] InputBox – simple static method to show InputBox in C#
- [C#] InputBox With Value Validation – improved InputBox class
- [C#] Hourglass Wait Cursor – how to change mouse cursor to hourglass
- [C#] Redraw a Whole Control on Resize – ensure a resized control is redrawn properly
- [C#] Separator Line on Form – how to simulate a bevel line on form
- [C#] Set DoubleBuffered Property – set protected property Control.DoubleBuffered
- [C#] Topmost Form at Application Level – don't overlap other applications
- [C#] Check Scrollbars Visibility – find out which scrollbars are visible
- [C#] Autoscroll (TextBox, ListBox, ListView) – autoscroll in common controls
Windows Services
- [C#] Create Windows Service in Visual Studio – create new service in VS 2005
- [C#] Install / Uninstall .NET Windows Service – how to install .NET services
- [C#] Start, Stop and Restart Windows Service – restart a service programmatically
- [C#] Get List of Windows Services – how to get list of installed services
Printing
- [C#] Combine Multiple PrintDocuments – how to join several PrintDocuments into one
Arrays and Collections
- [C#] Sorting Arrays – how to easily sort arrays of custom type
- [C#] Read-only Wrapper for a Collection – public property with read-only collection
Conversions
- [C#] String To Enum Conversion – how to convert string to enum value
- [C#] Reverse Bytes (Little/Big Endian) – how to reverse byte order
ADO.NET
- [C#] DataView RowFilter Syntax – DataView.RowFilter expression in examples popular