Access Modifiers Modifiers control the access levels for members. Non-nested Types Type Default Allowed namespace public public enum public public interface internal public, internal class internal public, internal struct internal public, internal delegate internal public, internal Nested and Member Accessibility Type Default Allowed namespace public public enum public public interface public none class private public, […]
C# – Nested Types
Nested Types Type defined within class or struct which defaults to private as are called nested types. The access modifiers for nested types can be : public, protected, internal, protected internal, private, private proteted. Nested types of a struct can be public, internal, or private. class OuterClass { class InnerClass { Nested () {} } […]
C# – Using Static
Static Static word can be used for class, methods, fields, etc. Using static usually boots performance and also allows faster invocation on the call. However you cannot use static to declare local variable in C#. You can use static with readonly field to initialize during runtime public static readonly; Static Class All members of the […]
C# – Fields
Fields Field is a member of a class or struct and it can be both instance fields or static. Instance specific is from the instance type, however it should only be used for private or protected accessibility. class { string name; public int Age = 10; } Fields have modifiers: Static: static Access modifier: public, […]
C# – Class
Class Is the most common reference type. class MyClassName { //methods, properties, fields, events, delegates, nested classes } Complex class has: Preceding the keyword class Attributes and modifiers such as Non-nested class modifiers public internal abstract sealed static unsafe partial private Following MyClassName Generic type parameters base class interfaces Within the braces Class members methods […]
C# – Operator Precedence and Associativity
Operator Precedence and Associativity When expression contains multiple operators then precedence and associativity decide the evaluation order. BODMAS is the order of precedence in general: B – Brackets first O – Of (orders: powers and square roots, cube roots, etc) D – Division (left to right) M – Multiplication (left to right) A – Addition […]
C# – Using Namespaces
Namespaces Namespaces are domain type names which makes it easier to find files and also it avoid name conflicts. They are independent of assemblies, which are units of deployment such as an .exe or .dll file. The namespace keyword defines a namespace for types within that block Example: namespace Outer.Middle.Inner { class Class1 {} class […]
C# – Variables and Parameters
Variables and Parameters A variable is a storage location that has modifiable value A variable can be local, parameter (value, ref, out), field (instance or static) or array element Stack and Heap It is a place where variables and constants reside Stack Block of memory for storing local variable and parameters. Logically grows and shrinks […]
C# – Arrays
Arrays Overview Inherit from System.Array class Is a reference type object int[] a = null; Is has fixed number of variables Arrays are stored in continous block of memory Arrays are denoted with square brackets after the element type char[] vowels = new char[5]; Square brackets are used to access the index of the array […]
C# – String Type
String Type Overview System.String Immutable sequence of Unicode characters Specified in double quotes Is reference type Escape sequence valid for char literals work inside strings eg string a = “Here’s a tab:\t”; Whenever backslash is needed you need to write twice string a1 = “\\\\server\\fileshare\\helloworld.cs”; Verbatim String Literals C# allows verbatim string literals, prefixed with […]