C# Language (How Do I in C#)
This topic links to help about widely used C# Language tasks. To view other categories of popular tasks explained in Help, see How Do I in C#.
The C# Language
What's New in Visual C#
Contains information about new language features, such as query expressions, collection initializers, lambda expressions, anonymous types, auto-implemented properties, partial methods, and more. Also points to information about what's new in the Visual C# IDE.C# Language Specification
Pointers to the latest version of the specification in Microsoft Word format.
Command Line
Main() and Command-Line Arguments (C# Programming Guide)
Explains the Main method, the entry point of your program, where you create objects and invoke other methods. There can only be one entry point in a C# program.How to: Access Command-Line Arguments Using foreach (C# Programming Guide)
Provides a code example that shows how to access the command-line parameters.How to: Display Command Line Arguments (C# Programming Guide)
Explains how to display arguments to the command line through the args string array.Main() Return Values (C# Programming Guide)
Explains the possible return values of the Main method.
Classes and Inheritance
How to: Initialize Objects without Calling a Constructor (C# Programming Guide)
Demonstrates how to use an object initializer.base (C# Reference)
Explains how to specify the base-class constructor that is called when creating instances of a derived class.How to: Know the Difference Between Passing a Struct and Passing a Class Reference to a Method (C# Programming Guide)
Contains a code example that shows that when a struct is passed to a method, a copy of the struct is passed, but when a class instance is passed, a reference is passed.Instance Constructors (C# Programming Guide)
Explains class constructors and inheritance.How to: Write a Copy Constructor (C# Programming Guide)
Contains a code example that demonstrates how a constructor of a class takes another object as an argument.How to: Implement User-Defined Conversions Between Structs (C# Programming Guide)
Contains a code example that defines two structs and demonstrates conversions between them.
Types
Types (C# Programming Guide)
Gives an overview of types in C# and the .NET Framework.Casting and Type Conversions (C# Programming Guide)
Shows how to use implicit and explicit conversions.Boxing and Unboxing (C# Programming Guide)
Contains examples that show how to box and unbox value types.How to: Safely Cast by Using as and is Operators (C# Programming Guide)
Shows how to cast without the risk of raising an InvalidCastException.How to: Convert a byte Array to an int (C# Programming Guide)
Shows how to convert from an array of bytes to a System.Int32 type.How to: Convert a string to an int (C# Programming Guide)
How to convert a string value such as "432" to an integer.How to: Convert Between Hexadecimal Strings and Numeric Types (C# Programming Guide)
How to convert a string value such as "0xA10" to an integer.
Arrays
Arrays as Objects (C# Programming Guide)
Contains a code example that displays the number of dimensions of an array.Jagged Arrays (C# Programming Guide)
Contains a code example that builds an array whose elements are themselves arrays.Passing Arrays as Arguments (C# Programming Guide)
Contains code examples that initialize a string array and pass it as a parameter to the PrintArray method, where its elements are displayed.Passing Arrays Using ref and out (C# Programming Guide)
Contains code examples that demonstrate the difference between out and ref when used to pass arrays to methods.How to: Use Implicitly Typed Local Variables and Arrays in a Query Expression (C# Programming Guide)
Explains how to use implicit typing for arrays and local variables.
Properties
How to: Implement an Immutable Class That Has Auto-Implemented Properties (C# Programming Guide)
Demonstrates how to create small classes that encapsulate a set of properties.How to: Declare and Use Read/Write Properties (C# Programming Guide)
Contains an example that shows how to declare and use read/write properties.How to: Define Abstract Properties (C# Programming Guide)
Contains a code example that shows how to define abstract properties.
Methods
Passing Value-Type Parameters (C# Programming Guide)
Contains code examples that demonstrate the various ways to pass value types.Passing Reference-Type Parameters (C# Programming Guide)
Contains code examples that demonstrate the various ways to pass reference types.How to: Implement and Call a Custom Extension Method (C# Programming Guide)
Explains how to create a static method that can be called as if it were an instance method on another type.
Events
How to: Subscribe to and Unsubscribe from Events (C# Programming Guide)
Shows how to subscribe to events published by other classes, including forms, buttons, list boxes, and so on.How to: Publish Events that Conform to .NET Framework Guidelines (C# Programming Guide)
Shows how to create events based on EventHandler and EventHandler<TEventArgs>.How to: Implement Interface Events (C# Programming Guide)
Shows how to implement events that are declared in interfaces.How to: Use a Dictionary to Store Event Instances (C# Programming Guide)
Explains how to use a hash table to store the event instances.How to: Raise Base Class Events in Derived Classes (C# Programming Guide)
Shows how to wrap base class events in protected virtual methods in order to make them callable from derived classes.How to: Implement Custom Event Accessors (C# Programming Guide)
Shows how to override the add and remove event accessors.
Interfaces
How to: Explicitly Implement Interface Members (C# Programming Guide)
Shows how to declare a class that explicitly implements an interface and how to access the members through the interface instance.How to: Explicitly Implement Members of Two Interfaces (C# Programming Guide)
Provides an example that displays the dimensions of a box in both metric and English units.
Generics
Generics in the .NET Framework
Explains the features and use of the new set of generic collections in the System.Collections.Generic namespace.default Keyword in Generic Code (C# Programming Guide)
Provides a code example that demonstrates how to use the default keyword for type parameters.Generic Methods (C# Programming Guide)
Introduces the syntax to declare a generic method. It also includes an example that demonstrates how to use generic methods in an application.Constraints on Type Parameters (C# Programming Guide)
Shows how to constrain type parameters to enable access to methods and properties of the types used to instantiate the generic class.Generic Delegates (C# Programming Guide)
Contains the syntax to declare generic delegates. It also includes important remarks about instantiating and using generic delegates as well as code examples.
Namespaces
- How to: Use the Namespace Alias Qualifier (C# Programming Guide)
Discusses the ability to access a member in the global namespace when the member might be hidden by another entity of the same name.
Iterators
How to: Create an Iterator Block for a Generic List (C# Programming Guide)
Provides an example of an array of integers that is used to build the list SampleCollection. A for loop iterates through the collection and yields the value of each item. Then a foreach loop is used to display the items of the collection.How to: Create an Iterator Block for a Generic List (C# Programming Guide)
Provides an example where a generic class Stack<T> implements a generic interface IEnumerator<T>. An array of the type T is declared and assigned values by using the method Push. In the GetEnumerator method, the values of the array are returned by using the yield return statement.
Delegates
Anonymous Functions (C# Programming Guide)
Describes how to use lambda expressions and anonymous methods to create delegate types.How to: Combine Delegates (Multicast Delegates)(C# Programming Guide)
Provides an example that demonstrates how to compose multicast delegates.How to: Declare, Instantiate, and Use a Delegate (C# Programming Guide)
Provides an example that illustrates how to declare, instantiate, and use a delegate.
Operator Overloading
- How to: Use Operator Overloading to Create a Complex Number Class (C# Programming Guide)
Shows how you can use operator overloading to create a complex number class Complex that defines complex addition.
Interoperability
- How to: Use Platform Invoke to Play a Wave File (C# Programming Guide)
Illustrates how to use platform invoke services to play a wave sound file on the Windows platform.
Unsafe code
How to: Use Pointers to Copy an Array of Bytes (C# Programming Guide)
Shows how to use pointers to copy bytes from one array to another.How to: Use the Windows ReadFile Function (C# Programming Guide)
Shows how to call the Windows ReadFile function, which requires the use of an unsafe context because the read buffer requires a pointer as a parameter.
Threading
Using Threads and Threading
Provides a list of topics that discuss the creation and management of managed threads and how to avoid unintended consequences.How to: Create and Terminate Threads (C# Programming Guide)
Provides an example that demonstrates how to create and start a thread, and shows the interaction between two threads running simultaneously within the same process.How to: Use a Thread Pool (C# Programming Guide)
Explains an example that shows how to use a thread pool.
Strings
How to: Search Strings Using Regular Expressions (C# Programming Guide)
Explains how to use the Regex class to search strings. These searches can range in complexity from very simple to making full use of regular expressions.How to: Concatenate Multiple Strings (C# Programming Guide)
Contains a code example that demonstrates how to join multiple strings.How to: Search Strings Using String Methods (C# Programming Guide)
Contains a code example that demonstrates how to use String methods to search for a string.How to: Split Strings (C# Programming Guide)
Contains a code example that demonstrates how a string can be split using the Split method.How to: Modify String Contents (C# Programming Guide)
Contains a code example that extracts the contents of a string into an array and then modifies some elements of the array.
Attributes
- How to: Create a C/C++ Union Using Attributes (C# Programming Guide)
Contains an example that uses the attribute Serializable to apply a specific characteristic to a class.
Working with DLLs
- How to: Create and Use C# DLLs (C# Programming Guide)
Demonstrates how to build and use a DLL by using an example scenario.
Assemblies
How to: Determine If a File Is an Assembly (C# Programming Guide)
Contains an example that tests a DLL to see if it is an assembly.How to: Load and Unload Assemblies (C# Programming Guide)
Explains how it is possible to load specific assemblies into the current application domain at run time.How to: Share an Assembly with Other Applications (C# Programming Guide)
Explains how to share an assembly with other applications.
Application Domains
Executing Code in Another Application Domain (C# Programming Guide)
Shows how to execute an assembly that has been loaded into another application domain.How to: Create and Use an Application Domain (C# Programming Guide)
Shows how operator overloading can be used to implement a three-valued logical type.
Samples
- Visual C# Samples
Contains links to open or copy the sample's files that range from Hello World Sample to Generics Sample (C#).