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






Windows Presentation Foundation /

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

GUI Windows Form /

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

Services Event /

Key Event 1System Event 1

Office /

Office Application 1Office Event 1
Word 3

LINQ /

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

XML LINQ /

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

Components /

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

Windows /

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

File Stream /

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

Database ADO.net /

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

XML /

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

2D Graphics /

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

Network /

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

Web Services /

Active Directory 14MessageQueue 2
SOAP 1

Thread /

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

Event /

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

Design Patterns /

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

Generics /

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

Reflection /

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

Security /

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

Development Class /

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

Collections Data Structure /

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

Regular Expressions /

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

Language Basics /

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

Class Interface /

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

Internationalization I18N /

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

Date Time /

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

Data Types /

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