Keywords
abstract | as |
base
bool
break
byte
case
catch
char
checked
class
const
continue
decimal
default
delegate
do
double
else
enum
event
explicit
extern
false
finally
fixed
float
for
foreach
goto
if
implicit
in
int
interface
internal
is
lock
longnamespace
Main() – this is the method where your program starts running. When the program is first loaded it will look for the Main method.
new
null
object
operator
out
override
params
private
protected
—–
public
The public keyword exposes members to other classes.
using System; namespace Rextester { public class Program { public static void Main(string[] args) { Panda p1 = new Panda ("Pan Dee"); Panda p2 = new Panda ("Pan Dah"); Console.WriteLine(p1.Name); Console.WriteLine(p2.Name); } } public class Panda { //instance field public string Name; //Constructor public Panda (string n) { //Assign the instance field Name = n; } } }
If instance field was declared private the program class will not be able to access it.
readonly
ref
return
sbyte
sealed
short
sizeof
stackalloc
Sealed
– Class cannot be inherited anymore
Static
– Static class cannot be instantiated, cannot use the new keyword, there is no instance variable. Contains only static members and is sealed.
static member – is callable when no instance of the class is created, not associated with an instance of the class
class SomeClass { public int InstanceMethod() { return 1; } public static int StaticMethod() { return 42; } } SomeClass instance = new SomeClass(); instance.InstanceMethod(); //Fine instance.StaticMethod(); //Won't compile SomeClass.InstanceMethod(); //Won't compile SomeClass.StaticMethod(); //Fine
– You need to initiate your class to call InstanceMethod
– You cannot invoke non static method from static method
string
struct
switch
this
throw
true
try
typeof
uint
ulong
unchecked
unsafe
ushort
using – reserved word to instruct the compiler to include a namespace. eg using System; Using statement ensures that an object is disposed of when it goes out of scope.
virtual
void – keyword means that the method we are about to describe does not return anything, the method will not return anything.
volatile
while
Contextual keywords
add
ascending
async
await
by
descending
dynamic
equals
from
get
global
group
in
into
join
let
nameof operator
The nameof operator returns the name of any symbol (type, member, variable, and
so on) as a string:
int count = 123; string name = nameof (count); // name is "count"
on
orderby
partial
remove
select
set
value
var
when
where
yield