Classes
Example:
using System;
namespace MyNamespace
{
// Class declaration
public class MyClass
{
// Fields
private int myField;
// Properties
public int MyProperty { get; set; }
// Constructors
public MyClass()
{
// Constructor code
}
// Methods
public void MyMethod()
{
// Method code
}
// Events
public event EventHandler MyEvent;
// Indexers
public int this[int index]
{
get { return index; }
set { /* Set the value at the specified index */ }
}
// Finalizer (destructor)
~MyClass()
{
// Finalizer code
}
// Nested class
private class NestedClass
{
// Nested class code
}
// Operator overloading
public static MyClass operator +(MyClass obj1, MyClass obj2)
{
// Operator code
return new MyClass();
}
// Static constructor
static MyClass()
{
// Static constructor code
}
// Static fields
public static int StaticField;
// Static methods
public static void StaticMethod()
{
// Static method code
}
// Constants
public const int MyConstant = 42;
}
// Enum
public enum MyEnum
{
Value1,
Value2,
Value3
}
// Struct
public struct MyStruct
{
// Struct code
}
// Interface
public interface IMyInterface
{
// Interface members
void Method1();
void Method2();
}
}Last updated