C# / C Sharp examples (example source code) Organized by topic

Windows Presentation Foundation /

3D 15AccessText 5Animation 64Application 24
ApplicationCommand 11BackgroundWorker 10Binding 49BitmapEffect 10
BitmapSource 4Border 11Brush 11Button 37
Canvas 17CheckBox 12Clip 4CollectionViewSource 3
Color 20ComboBox 11Command 15Common Dialogs 1
ContextMenu 3ControlTemplate 15Coordinate 2Cursor 2
Curve 1DataContextProperty 2DataTemplate 6DataTrigger 3
DependencyProperty 5DependencyPropertyDescriptor 1Dispatcher 7DockPanel 10
DoubleAnimation 8Drag Drop 1DrawingBrush 10DrawingGroup 2
DrawingImage 6Ellipse 14Event 22EventSetter 1
EventTrigger 8Exception 13Expander 2FlowDocument 33
Focus 1Font 6Forms 3Frame 7
Geometry 18GeometryGroup 2Glyphs 1Grid 65
GridSplitter 7GroupBox 2HeaderedItemsControl 1HierarchicalDataTemplate 2
Hyperlink 2Image 22ImageBrush 17InputBinding 1
InputGestureCollection 1ItemsControl 4ItemsSource 1IValueConverter 6
JpegBitmapEncoder 2Key Event 15Label 5LayoutInformation 1
Line 7LinearGradientBrush 23ListBox 49ListView 15
Margin 5Matrix3D 8MediaElement 11Menu 15
MessageBox 5Mouse 27NavigationService 1NavigationWindow 1
ObjectDataProvider 5ObservableCollection 5Padding 4Page 6
Panel 14PasswordBox 3Path 46Polygon 20
Polyline 21Popup 8PresentationTraceSources 1Print 4
ProgressBar 6RadialGradientBrush 4RadioButton 10Rectangle 22
RenderTransform 23RepeatButton 3Resource 31RichTextBox 8
RoutedCommand 16ScrollViewer 5Separator 1Slider 20
SolidColorBrush 12SoundPlayerAction 2Span 1Speech Synthesis 2
StackPanel 10StatusBar 10Storyboard 8Stroke 15
Style 21SystemParameters 1TabControl 11TextBlock 39
TextBox 28TextDecoration 10TextRange 1Thread 9
Thumb 2Timeline 2Timer 3ToolBar 10
ToolTip 17TreeView 11UI Element 19UniformGrid 1
Validation 3vb 23Viewbox 1VisualBrush 7
Window 54WrapPanel 8Xaml 17XamlReader 2
XmlDataProvider 11xps 2

GUI Windows Form /

Agent Help 2Anchor 5Bitmap 5Border 2
Button 20Calendar 4CheckBox List 2CheckBox 8
Clipboard 6Clock 1Color Dialog 4ComboBox 7
Console 1ContentAlignment 1Control Anchor 1Control 7
Cursor 6Data Binding 2Data Validation 2DataGrid Data Binding 2
DataGrid 1DateTimePicker 3Dialog 8Directory Tree 1
Docking 9Drag Drop 5Editor 1Focus 2
Font Dialog 2Font 13Form Event 20Form Frame Window 26
Form Style 6Full Screen 1GroupBox 3Help System 2
ImageList 2Irregularly Shaped Forms 10Label 7Layout 1
LinkLabel 3ListBox Data Binding 6ListBox 14ListView 17
MaskedTextBox 2MDI 10Menu 7MenuItem 11
MessageBox 7Mouse On Form 1Mouse 1NativeWindow 1
Open File Dialog 10PageSetupDialog 1Paint 1Panel 5
Password 2PictureBox 8Popup Menu 1Print Dialog 2
Print 15PrinterSettings 4ProgressBar 2Property Grid 1
RadioButton 9ResourceManager 1ResourceReader 2ResourceWriter 3
ResXResourceWriter 2RichTextBox 7SaveFileDialog 4Scrollable 2
ScrollBar 4Splitter 6StatusBar 12System Tray Icon 1
Tab 2TextBox 16Thread and UI 4Time 1
ToolBar 5ToolStripMenuItem 2Tooltips 5Track Bar 1
Tray Icon 1TreeView 13Unicode Display 8UpDown 5
User Control 5Validation 2Web Browser 4

Services Event /

Key Event 1System Event 1

Office /

Office Application 1Office Event 1Word 3


Aggregate 4All 4Any 6Average 5
Cast 1Class Init 1Compound from 6Concat 6
Contains 6Count 6DataGridView 1DefaultIfEmpty 3
Deferred Query 7Distinct 5ElementAt 4ElementAtOrDefault 3
Enumerable.Empty 1Enumerable.Range 2Enumerable.Repeat 2Enumerable 1
Equals 1Except 4Expression 3Extension Method 4
Filter 4First 5FirstOrDefault 6foreach loop 1
Group 3GroupBy 5GroupJoin 1Index 4
Intersect 4Join 5Lambda 8Last 2
LastOrDefault 4LongCount 2Max 8Min 7
Nested Query 2Object Query 4OfType 3OrderBy 13
OrderByDescending 1Projection 1Prototype 4Query 7
Restriction 1Reverse 2select new 4select 14
SelectMany 3SequenceEqual 4Single 3SingleOrDefault 5
Skip 5SkipWhile 5SQL 1Sub Query 2
Sum 6Take 6TakeWhile 4ThenBy 2
ThenByDescending 1ToArray 6ToDictionary 6ToList 4
ToLookup 4Union 5var 5where 17


AddAfterSelf 1AddBeforeSelf 1AddFirst 2Ancestors 6
AncestorsAndSelf 3Attribute 26Children 4DescendantNodes 1
DescendantNodesAndSelf 3Descendants 8DescendantsAndSelf 1Elements 4
ElementsAfterSelf 1Event 2InDocumentOrder 1Load Save 23
Namespace 9Nodes 23NodesAfterSelf 1OfType 2
Query 10Remove 2RemoveAll 1ReplaceAll 1
Schema Validating 6SetElementValue 1Traverse 4XAttribute 19
XCData 1XComment 3XDeclaration 3XDocument transformation 2
XDocument 33XDocumentType 2XElement Update 3XElement 44
XML Convert 7XML Tree 5XName 1XNamespace 16
XObject 9XPath 2XProcessingInstruction 3XStreamingElement 1
XText 1

Components /

AboutBox 1Chart 1Clock 1ComboBox 3
Gradient Panel 1Marquee Label 1Numeric TextBox 1Progress Bar 1
Screen Capture 1

Windows /

Clipboard 1Event Log 6Excel 1File Security Permission 5
IIS 1ManagementClass 5ManagementObjectSearcher 1Message 2
Registry Permission 2Registry 6Windows API 14Windows Principal 6
Windows Service 3Word 1

File Stream /

Ascii String Read Write 6Asynchronous Input output 3Binary Read Write 17Bit Convert 2
BufferedStream 2Byte Array 37Byte Read Write 8CSV 4
DeflateStream 1Directory 69Drive 8Encode 7
File Attributes 2File Command 23File Cryptography 5File Info 16
File MemoryStream 4File Name 17File Read Write 21File Stream Encode 1
File System 5File Util 42File 38FileSecurity 1
FileStream 27FileSystemWatcher 4FileVersionInfo 14GZipStream 3
IDeserializationCallback 1IsolatedStorageFile 4Memory Stream 10Path 45
Random Read 1Serialization SOAP 3Serialization 26Stream Null 1
Stream Read Write 35Stream 24StringWriter 6Temp File 2
Text File Read Write 23UTF8 UTF16 5Zip 3

Database ADO.net /

Access 6ADO.NET Events 1BindingManagerBase 1Connection String 2
Create Database 1Create table 3CSV 2Data Bind DataGrid 3
Data Bind Label 1Data Bind ListBox 2Data Bind TextBox 5Data Binding 6
Data Fill ListView 1Database to XML 3Database Utilities 1DataBinding TrackBar 1
DataGrid 6DataGridView 7DataRelation 3DataRow 2
DataRowView 1DataSet 19DataTable 6DataTableMapping 1
DataView 3DB2 2DbProviderFactory 2Delete 4
IDbConnection 1Insert 5Introduction 1Load Image 1
Many to Many 1MySQL 1ODBC Connection 1ODBC 2
OdbcCommand 5OleDbCommand 9OleDbConnection 8OleDbDataReader 7
OleDbReader 1OleDbTransaction 4Oracle 4Result Set 3
Row Count 2Select Query 2Select 3SQL Data Type 4
SQL Events 4SQL Server Connection Pool 1SQL Utilities 2SqlCommand Parameters 1
SqlCommand 14SqlCommandBuilder 8SqlConnection 11SqlConnectionStringBuilder 1
SqlDataAdapter 3SqlDataReader 11SqlDataSourceEnumerator 1SqlException 4
Store Procedure 9Table Column 4Table Schema 6Transactions 6
Update 8XML Database 6


Attribute 32DOM 13Namespace 2Node Type 6
Schema 14Serialization 1SOAP 2Stylesheet 1
Tag 1XML Create 3XML DataGrid 3Xml Encoding 2
Xml Format 3XML ListView 1XML Node 30XML Read 54
Xml Serialization 15XML Transform 7XML Tree 3XML Write 8
XmlDocument 11XmlElement 26XmlTextReader 23XmlTextWriter 15
XmlWriter 20XPath 16XPathNavigator 33

2D Graphics /

Ani File 1Animation 11Arrow 1Bitmap 32
Blend 1Brush 10Clip 5Color Matrix 3
Color 42Coordiate 2Curve 6Dash Pen 5
Double Buffer 2Drag and Draw 3Ellipse 1FillMode 2
Font Style 7Font Unit Metrics 6Font 10FontFamilies 5
Gif Animation 2Gradient 13Graphics File 1Graphics Unit 4
Graphics 50Hatch Brush 10Icon Image 13Image Decoder 1
Image 45ImageAttributes 1Interpolation Mode 2JPG 3
Line Cap 9Line Join 3Line 11LinearGradientBrush 4
Matrix 6Mouse Draw 5Path 19PathGradientBrush 7
Pens 20Pie 2Pixel 3Point 2
Polygon 1Pyramid 1Rectangle 5Region Clip 2
Region 13Rotate 4Scale 1Screen 3
Scrolling 2Smooth Paint 2Smoothing Mode 4SolidBrush 2
String Format 7StringAlignment 5StringTrmming 6SystemBrushes 1
SystemColors 1SystemPens 1Text Justify 11Text Rendering 9
Text 17Texture 11Transform 7wmf file 5

Network /

Broadcast 3Captcha 1CDO 1Chat 4
Cookie 2Crypto Connection 3Data Send Receive 4DNS 10
Dsml 2FtpWebResponse 2HTML 14Http Channel 3
HTTP Put 2HttpWebRequest 5IP Address 30IPEndPoint 2
IPHostEntry 1Json 6Mac Address 2Mail 12
Mime Type 3Net Mask 1NetworkInterface 12NetworkStream 5
Ping 9Query String 4SNMP 1Socket Connection 11
Socket Listener 3TCP Client 13TCP Server 15TCP Stream 1
Udp Client 13Udp Server 4URI 62UriBuilder 6
Web Client 29Web Crawler 7Web Proxy Server 1Web Request Response 18
Web Server 1WebHeaderCollection 5WebPermission 10

Web Services /

Active Directory 14MessageQueue 2SOAP 1

Thread /

AutoResetEvent 1Monitor 3Mutex 3Producer Consumer 3
Thread Abort 2Thread and GUI 2Thread Creation 9Thread Interupt Destroy 2
Thread Join 2Thread Lock 3Thread Monitor Manage 4Thread Pool 6
Thread Properties 5Thread Sleep 2Thread Start Wait 3Thread Sync 16
Threads Error 1ThreadStart 1WaitCallback 1

Event /

Key Event 14Message 2Mouse Event 19System Event 2
UI Event 4

Design Patterns /

Adapter Pattern 1Chain Pattern 1Composite Pattern 1Facade Pattern 1
Factory Pattern 1Observer Pattern 1Proxy Pattern 2Singleton Pattern 2
Strategy Pattern 1Template Pattern 1

Generics /

Generic Class Hierarchy 5Generic Class 9Generic Collections 10Generic Constraint 13
Generic delegate 6Generic Interface 3Generic Method 4Generic Objects 1
Generic Parameters 1Generic Serialization 1Generic struct 1Generic Tree 3
Generic Type 11IComparable 1IEnumerable 1IEnumerator 1
Queue 1where clause 1

Reflection /

Activator 4AppDomain 17Assembly 46AssemblyName 4
Attributes 26Base Type 2BindingFlags 9ConstructorInfo 9
Event 9FieldInfo 27Interface 3MemberInfo 20
MethodInfo 18Module 9ParameterInfo 11PropertyInfo 43
Type 73Version 1

Security /

Checksum 6CRC 5Encrypt Decrypt 15FileIOPermissionAccess 2
Hash 13HashAlgorithm 1KeyedHashAlgorithm 1MD5 14
Password 5PermissionSet 1PrincipalPermission 3RegistryPermission 2
SecureString 3SecurityIdentifier 1SecurityManager 2SHA1Managed 11
X509Certificates 3

Development Class /

AppDomain 7Application Event 8Application 2Assembly Permission 4
Assert Debug 2Attribute 1Base64 15BitConverter 22
Buildin Exceptions 14Cache 3Command Line 2Console Input Output 28
Console 17ConsoleKey 1Debug Trace 19Decoder 4
DLL 5Encoder 4Environment Settings 50EventArgs 1
Evidence 1Exception 3External API 1FormsAuthentication 1
Garbage Collection 22Geometry 18Guid 7Hash Code 2
IAsyncResult 2ICryptoStream 2Identity 2ini file 1
Interlocked 5LDAP 1Log 16Macro 4
ManualResetEvent 3Marshal 1Matcher 6Math 75
MediaPlayer 1Mono 1Number Format 22Parse 1
Parser 2Polynomial 2Process 22ProcessStartInfo 2
Random 31RandomNumberGenerator 1Reflection Assembly 20RegexCompilationInfo 2
Registry 17Regular Expression 41Resource ResX 18Round 3
SerialPort 5Service 1Sound 1SoundPlayer 1
StackAlloc 1Start Process 1Stopwatch 2String Info 2
StringBuilder 23StringWriter 1System Object Method 11System Registry 1
SystemEvent 2SystemInfo 12SystemSounds 1Timer 10
Trace 5UIPermission 1Vector 9Version 4
Volatile 1WCF 2WMI 2XML Documentation 10
Xna 7

Collections Data Structure /

Array Dimension 18Array Sort 2Array Util 49Array 42
ArrayList 23BitArray 12BlockingCollection 1CaseInsensitiveHashCodeProvider 5
CollectionBase 3CollectionsUtil 3Compare 7ConcurrentBag 1
ConcurrentQueue 1ConcurrentStack 1Dictionary 18DictionaryBase 10
HashSet 9Hashtable 18ICollection 25IComparable 4
IComparer 4IDictionary 1IEnumerable 45LinkedList 8
List 46ListDictionary 9NameObjectCollectionBase 11ObservableCollection 2
OrderedDictionary 3Queue 16ReadOnlyCollection 1Search 1
Set 4Sort 8SortedDictionary 1SortedList 24
Stack 14StringCollection 6StringComparer 7StringDictionary 7
Tree 1Your LinkedList 1

Regular Expressions /

Email 4Group Capture 1Match 14Split 2
Url 1Validation 10Zip Code 1

Language Basics /

Alias 2as 2At 3Attribute 18
Break 3Comments 2Constant 2Continue 1
delegate anonymous 7Delegate Async 4delegate Event 14delegate 25
DLL Library 5Event Handler 3Exception Class 17Exception Finally 7
Exception Stack 6Exception Throw 10Exception Try Catch 23Exit 1
Expressions 2fixed 1for 25Foreach 11
Function Definition 6Function Overloading 1Function Parameters 9Goto 4
If 12Internal 1is 4Main 11
Mod 2NameSpace 14null 1Operator bitwise 18
Operator is as 7Operators 32Parameters Passing 21params 5
Pointer Unsafe 12Preprocessor Directives 12Ref Out 4Reference Equal 1
sizeof 2stackalloc 5StringBuffer StringBuilder 13Switch 12
throw 3Try Catch 4Unsafe Code 17Using 2
Variable Definition 24Variable Scope 5While 14

Class Interface /

Abstract Class 6Class Access Modifiers 8Class Definition 25Class Deriving 2
Class Inheritance 17Class Method 16Class Variables 7Clone 6
Constructor 16Destructor 6IComparable 2IComparer 2
ICustomFormatter 1IDisposable 6IEnumerable 8IEnumerator 4
IFormattable 1Indexer 19Interface 28ISerializable 1
Object Cast 6Object Copy 1Object Instance 7Operator Overloading 14
Overloading Method 3Override Virtual 12params 1private 1
Properties 18public 5readonly 4Sealed 2
Static 12struct 17This 3ToString 7

Internationalization I18N /

ASCIIEncoding 11CultureAndRegionInfoBuilder 1CultureInfo I18N 13Encoding 25
I18N 2NumberFormatInfo 4RegionInfo 4Unicode UTF16 9
UnicodeEncoding 18UTF7Encoding 1UTF8Encoding 22

Date Time /

Calendar 10Date Time Calculation 11Date Time Format 67Date Time Util 44
Date Time 53DateTimeFormatInfo 20DateTimeOffset Calculation 15DateTimeOffset Format 34
DateTimeOffset Parse 21DateTimeOffset 45GregorianCalendar 13Time Span Parse 14
TimeSpan Format 13TimeSpan 51TimeZone 14TimeZoneInfo 22

Data Types /

BigInteger 28Binary Bit 11bool 10Boxing Unboxing 11
byte format 2byte 34cast 5Casting Conversions 31
Char 21checked unchecked 7Complex 37Convert 36
decimal 38double format 60double parse 16double 17
Enum format 4Enum 39float format 10float parse 16
float 14HEX 29IConvertible 1IFormattable 3
IndexOutOfRangeException 1int format 24int parse 4int 42
Literal 2long 5Matrix 4Nulllable 7
Number 30NumberFormatInfo 22NumberStyles 16octal 3
OverflowException 2Parse 9Partial Type 1sbyte 13
short 2String Array 15String Compare 12String Format 43
String Replace 9String Search 10String Split 29String Util 56
String 42Tuple 3Type 4ulong 1
ushort 1