You are on page 1of 25

Need a discount on popular programming courses? Find them here.

View offers

Home / Articles / C# / Download C# Cheat Sheet PDF for Your Quick Reference Disclosure: Hackr.io is supported by its
audience. When you purchase through
Ramya Shankar | 12 Dec, 2022 links on our site, we may earn an
affiliate commission.

Download C# Cheat Sheet PDF


for Your Quick Reference

C# Introduction

Object-oriented language, with syntax similar to C++ and Java.


Type safe
Component oriented, structured language
Automatic garbage collection
Rich set of libraries
Conditional compilation

Syntax
Case sensitive
Comments are typed within // (single-line) or /**/ (multi-line)
Code is typed inside code blocks {}
Line termination is done using semicolon ;
Supports comment task highlighters like TODO: , NOTE: ,
WARN: etc…

Variables
<datatype> <variablename> = <initialvalue>;

Variables should start with underscore and cannot contain


white spaces.
It can contain numbers but should always start with a capital
letter.
It cannot contain any symbols (other than underscore).

Naming Conventions

Class StudentClass

Method GetMarks
Local variable firstName

Private variable avgMarks

Constant Percentile

Data types

Int Integer values like 1234, 10000

Double 64-bit floating-point, 3.145644

Float Floating point number, 3.1454

String Set of characters, “Welcome.”

Byte 8bit unsigned integer

Char 16 bit Unicode character, ‘A.’

Long 64 bit signed integer, -9.0789

High precision decimal


Decimal
numbers

Bool True or false Boolean value

Value data type contains its


Enums
value

value type that is used to


Struct
represent a record

Initialisation of variables

int i = 7;
byte b = 255;
String s = “hackr.io”;
char c = ‘h’;

Constant values

const String lastDayOfWeek = “Friday”;

String Data type conversion

Method Description Example

Convert string into


AsInt(), integer intVal = str.AsInt();
IsInt() Check If the input is str.IsInt()
int
Convert string into
floatVal =
AsFloat(), float
str.AsFloat();
IsFloat() Check if the input is
str.IsFloat()
float

Convert string into


decVal =
AsDecimal() decimal
str.AsDecimal();
IsDecimal() Check if input is
str.IsDecimal()
decimal

Convert string into dateVal =


AsDateTime() datetime type str.AsDateTime();

IsDateTime() Check if input is


date-time str.isDateTime();

Convert string into


boolVal =
AsBool() Boolean
str.AsBool();
IsBool() Check if input is
str.IsBool();
Boolean

Convert another myVal = 1111;


data type like int,
ToString() strVal =
array, list etc into
String myVal.ToString();

Operators

Operator Description

= Assigns variable value. (i = 10)

Adds a value or variable. (i + j)


+
or (i + 3)

Subtracts values or variables.


-
(i – j)

Multiplies values or variables.


*
(i*j)

/ Divides values or variables. (i/j)

+= Increments a variable. ( i+=1)

-= Decrements a variable. (i-=1)

Equality. Returns true if values


==
are equal. (i==10)

Inequality. Returns true if


!=
values are not equal. (I != 10)

< Less Than (i < 5)


> Greater Than (i > 5)

<= Less Than or Equal to (i <= 5)

>= Greater than equal to (i >= 5)

String concatenation
+ (“Welcome to ” +
websiteName)

Call methods, constant


. variables etc..

arrVal.ToString()

Calculations, passing
() parameters etc…

(i+10)*(i-10); multiply(i, j)

Access values in arrays or


[]
collections. name[i]

Reversing Boolean value


!
if (!isMatching)

Logical AND
&&
if (isSingle && isMatching)

sizeof() returns the size of a data type

returns the type of object –


typeof()
string, integer etc…

Suggested Course

C# Basics for Beginners: Learn C# Fundamentals by Coding

String Operations

String Functions Definitions Example

Make clone of
Clone() str2 = str1.Clone()
string.

Compare
Programming two
Data Science DevOps Design Login
strings and returns
integer value as
CompareTo() str2.CompareTo(str1) In this article
output. It returns 0
for true and 1 for C# Introduction
false.

checks whether
specified character
Contains() or string is exists or str2.Contains(“hack”)
not in the string
value.
checks whether
specified character
EndsWith() str2.EndsWith(“io”);
is the last character
of string or not.

compares two
string and returns
Equals() Boolean value true str2.Equals(str1)
as output if they are
equal, false if not

returns HashValue
GetHashCode() str1.GetHashCode()
of specified string.

returns the
GetType() System.Type of str1.GetType()
current instance.

returns the
Stystem.TypeCode
GetTypeCode() str1.GetTypeCode()
for class
System.String.

Returns the index


position of first
IndexOf() str1.IndexOf(“:”)
occurrence of
specified character.

Converts String into


lower case based
ToLower() str1.ToLower();
on rules of the
current culture.

Converts String into


Upper case based
ToUpper() str1.ToUpper();
on rules of the
current culture.

Insert the string or str1.Insert(0,


character in the “Welcome”);
Insert()
string at the str1.Insert(i, “Thank
specified position. You”);

Check whether this


IsNormalized() string is in Unicode str1.IsNormalized()
normalization form

Returns the index


position of last
LastIndexOf() str1.LastIndexOf(“T”);
occurrence of
specified character.

returns length of
Length str1.Length;
string.
deletes all the
characters from
Remove() beginning to str1.Remove(i);
specified index
position.

replaces the
Replace() specified character str1.Replace(‘a’, ‘e’);
with another

str1 = “Good
morning and
Welcome”;
This method splits
String sep =
Split() the string based on
{“and”};
specified value.
strArray =
str1.Split(sep,
StringSplitOptions.No

Checks whether
the first character
StartsWith() str1.StartsWith(“H”)
of string is same as
specified character.

This method
Substring() str1.Substring(1, 7);
returns substring.

Converts string into


ToCharArray() str1.ToCharArray()
char array.

It removes extra
whitespaces from
Trim() str1.Trim();
beginning and
ending of string.

Modifiers

field or function accessible by


any other code in the same
public
assembly or another assembly
that references it

Only available by code in the


private
same class or struct

Only accessible by code in the


protected same class or struct or a
derived class

Accessible by any code in the


internal same assembly, but not from
another assembly

protected internal Accessible by any code in the


same assembly, or by any
derived class in another
assembly

to indicate a class that is


intended only to be a base
abstract
class of other classes (has to
be extended by other classes)

Indicates that the modified


method, lambda expression, or
async
anonymous method is
asynchronous

Specifies that the value of the


const field or the local variable
cannot be modified (constant)

event Declares an event

Indicates that the method is


extern
implemented externally

Explicitly hides a member


new
inherited from a base class

Provides a new
implementation of a virtual
override
member inherited from a base
class

Defines partial classes,


partial structs, and methods
throughout the same assembly

Declares a field that can only


be assigned values as part of
read-only
the declaration or in a
constructor in the same class

Specifies that a class cannot


sealed
be inherited

Declares a member that


belongs to the type itself
static instead of to a specific object,
e.g., for static class or method,
no object needs to be created

unsafe Declares an unsafe context

Declares a method or an
accessor whose
virtual implementation can be
changed by an overriding
member in a derived class

volatile Indicates that a field can be


modified in the program by
something such as the
operating system, the
hardware, or a concurrently
executing thread

Date/Time formatting

DateTime dt = new
gives output as –
DateTime();
01-01-0001 00:00:00
dt.ToString();

dt = DateTime.Now; gives current date and time

gives the specified date in


dt = new DateTime(yyyy, MM,
yyyy-MM-dd format. Time will
dd);
be 00:00:00

dt = new DateTime(yyyy, MM, gives specified date and time


dd, hh, min, ss); in the 24-hour format

dt = new DateTime(yyyy, MM,


dd, hh, mm, ss); gives only the date, with the
time part set to 00:00:00
dt1 = dt.Date;

prints only the date part by


DateTime.Now.ToShortDateString()
completely omitting the time
part

prints the whole date and time


based on region, month is
DateTime.Now.ToLongDateString()
printed in letters (JAN, FEB
etc.. ) rather than number (01,
02)

DateTime format specifiers

Format specifier Name Description

Represents a
custom DateTime
format string
defined by the
current
ShortDatePattern
d Short date pattern property.

For example, the


custom format
string for the
invariant culture is
"MM/dd/yyyy."

D Long date pattern Represents a


custom DateTime
format string
defined by the
current
LongDatePattern
property.
For example, the
custom format
string for the
invariant culture is
"dddd, dd MMMM
yyyy."

Represents a
combination of the
Full date/time long date (D) and
f
pattern (short time) short time (t)
patterns, separated
by a space.

Represents a
custom DateTime
format string
defined by the
current
FullDateTimePattern
Full date/time property.
F
pattern (long time)
For example, the
custom format
string for the
invariant culture is
"dddd, dd MMMM
yyyy HH:mm: ss."

Represents a
combination of the
General date/time short date (d) and
g
pattern (short time) short time (t)
patterns, separated
by a space.

Represents a
combination of the
General date/time short date (d) and
G
pattern (long time) long time (T)
patterns, separated
by a space.

Represents a
custom DateTime
format string
defined by the
current
MonthDayPattern
M or m Month day pattern property.
For example, the
custom format
string for the
invariant culture is
"MMMM dd."

o Round-trip Represents a
date/time pattern custom DateTime
format string using
a pattern that
preserves time
zone information.
The pattern is
designed to round-
trip DateTime
formats, including
the Kind property,
in text. Then the
formatted string
can be parsed back
using Parse or
ParseExact with the
correct Kind
property value.
The custom format
string is "yyyy'-
'MM'-'dd'T'HH':'
mm': 'ss.fffffffK."

The pattern for this


specifier is a
defined standard.
Therefore, it is
always the same,
regardless of the
culture used or the
format provider
supplied.

Represents a
custom DateTime
format string
defined by the
current
RFC1123Pattern
property. The
pattern is a defined
standard, and the
property is read-
only. Therefore, it is
always the same
regardless of the
culture used, or the
format provider
supplied.
The custom format
R or r RFC1123 pattern
string is "DDD, dd
MMM yyyy HH':'
mm': 'ss 'GMT'".

Formatting does
not modify the
value of the
DateTime object
that is being
formatted.
Therefore, the
application must
convert the value to
Coordinated
Universal Time
(UTC) before using
this format
specifier.

s Sortable date/time Represents a


pattern; conforms custom DateTime
to ISO 8601 format string
defined by the
current
SortableDateTimePat
property. This
pattern is a defined
standard, and the
property is read-
only. Therefore, it is
always the same
regardless of the
culture used, or the
format provider
supplied.
The custom format
string is "yyyy'-
'MM'-
'dd'T'HH':'mm': 'ss."

Represents a
custom DateTime
format string
defined by the
current
ShortTimePattern
t Short time pattern property.

For example, the


custom format
string for the
invariant culture is
"HH:mm."

Represents a
custom DateTime
format string
defined by the
current
LongTimePattern
T Long time pattern property.

For example, the


custom format
string for the
invariant culture is
"HH:mm: ss".

u Universal sortable Represents a


date/time pattern custom DateTime
format string
defined by the
current
UniversalSortableDat
property. This
pattern is a defined
standard and the
property is read-
only. Therefore, it is
always the same
regardless of the
culture used or the
format provider
supplied.
The custom format
string is "yyyy'-
'MM'-'dd
HH':'mm':'ss'Z'".
No time zone
conversion is done
when the date and
time is formatted.
Therefore, the
application must
convert a local date
and time to
Coordinated
Universal Time
(UTC) before using
this format
specifier.

Represents a
custom DateTime
format string
defined by the
current
FullDateTimePattern
property.

This pattern is the


Universal sortable same as the full
U
date/time pattern date/long time (F)
pattern. However,
formatting operates
on the Coordinated
Universal Time
(UTC) that is
equivalent to the
DateTime object
being formatted.

Represents a
custom DateTime
format string
defined by the
current
YearMonthPattern
Y or y Year month pattern property.

For example, the


custom format
string for the
invariant culture is
"yyyy MMMM".

Custom patterns –
"MM'/'dd yyyy" 03/17 2019

"dd.MM.yyyy" 17.03.2019
Custom format 03.17.2019 06:23
"MM.dd.yyyy
HH:mm" Tuesday, march
"dddd, MMMM (2019) : 06:23:00
(yyyy): HH:mm:ss"
An unknown
Any other single specifier throws a
(Unknown specifier)
character runtime format
exception.

Arrays
For creating, modifying, sorting and searching arrays.

PROPERTY DESCRIPTION EXAMPLE

string[] arrVal =
new string[]
checks whether the {“stud1”, “stud2”,
IsFixedSize Array has a fixed “stud3”};
size.

arrVal.IsFixedSize;

Checks whether
IsReadOnly the Array is read- arrVal.IsReadOnly;
only.

Checks whether
access to the Array
IsSynchronized arrVal.IsSynchronized
is synchronized
(thread safe).

Gets the total


number of elements
Length in all the arrVal.Length;
dimensions of the
Array.

Length in 64-bit
LongLength arrVal.LongLength;
integer

Gets the rank


(number of
dimensions) of the
Array. For example,
Rank a one-dimensional arrVal.Rank;
array returns 1, a
two-dimensional
array returns 2, and
so on.

Gets an object used


SyncRoot to synchronize arrVal.SyncRoot;
Array access

Returns a read-only
AsReadOnly() wrapper for the Array.AsReadOnly(arr
specified array.
Searches a value in
Array.BinarySearch(a
a one-dimensional
obj); where obj is
BinarySearch() sorted array using a
the object to be
binary search
searched.
algorithm.

Array.Clear(arrVal,
0, 2);
Sets a range of
elements in an If arrVal is an array
Clear() array to the default of integers, the
value of each elements at
element type. position 0 to 2 will
be set to zero after
doing Clear().

Create a shallow
Clone() Array.Clone(arrVal);
copy of the Array.

Array.ConstrainedCop
0, destArr, 3, 5);
Copies a range of
where srcArr is the
elements from an
source array,
Array starting at the
specified source 0 is the start index
index and pastes from where copy
them to another should begin,
Array starting at the
ConstrainedCopy() destArr is the
specified
destination index. destination array,
Guarantees that all
3 is the place
changes are
where copy should
undone if the copy
start in the
does not succeed
destination array,
completely.
5 is the number of
elements to copy

conArr =
Converts an array
Array.ConvertAll(arrV
of one data type to
ConvertAll() new
an array of another
Converter<dtype1,
data type.
dtype2> (method));

Copies a range of Array.Copy(srcArr,


elements in one destArr, 2);
Array to another
Copy() copies first two
Array and performs
type casting and elements from
boxing as required. srcArr to destArr

Copies all the


elements of the Array.CopyTo(destArr
current one- 4);
CopyTo() dimensional array
to the specified copy starts from
one-dimensional index 4
array.

Initializes a new
Array.CreateInstance
CreateInstance() instance of the
length);
Array class.
Returns an empty
Empty() arrVal.Empty()
array.

Determines
whether the
Equals() specified object is arrVal.Equals(arrVal2)
equal to the current
object.

Determines
whether the
specified array
contains elements Array.Exists(srcArr,
Exists()
that match the “<elementname>”);
conditions defined
by the specified
predicate.

Searches for an
element that
matches the
conditions defined Array.Find(arrVal,
Find() by the specified <matching
predicate, and pattern>);
returns the first
occurrence within
the entire Array.

Retrieves all the


elements that
Array.FindAll(arrVal,
match the
FindAll() <matching
conditions defined
pattern>);
by the specified
predicate.

Searches for an
element that
matches the
conditions defined
by a specified Array.FindIndex(arrVa
FindIndex() predicate, and <matching
returns the zero- pattern>);
based index of the
first occurrence
within an Array or a
portion of it.

Searches for an
element that
matches the
conditions defined Array.FindLast(arrVal,
FindLast() by the specified <matching
predicate, and pattern>);
returns the last
occurrence within
the entire Array.

FindLastIndex() Searches for an Array.FindLastIndex(a


element that <matching
matches the pattern>);
conditions defined
by a specified
predicate, and
returns the zero-
based index of the
last occurrence
within an Array or a
portion of it.

Loops through each


element of the Array.ForEach(arrVal,
ForEach()
array and performs Action)
the specified action

Returns an
GetEnumerator() IEnumerator for the arrVal.GetEnumerator
Array.

default hash
GetHashCode() arrVal.GetHashCode(
function.

Gets a 32-bit
integer that
represents the
arrVal.GetLength(i)
GetLength() number of elements
where i is an integer
in the specified
dimension of the
Array.

Gets a 64-bit
integer that
represents the
arrVal.GetLongLength
GetLongLength() number of elements
where i is an integer
in the specified
dimension of the
Array.

Gets the index of


the first element of
arrVal.GetLowerBoun
GetLowerBound() the specified
where i is an integer
dimension in the
array.

Gets the Type of


GetType() the current arrVal.GetType()
instance.

Gets the index of


the last element of
arrVal.GetUpperBoun
GetUpperBound() the specified
where i is an integer
dimension in the
array.

Gets the value of


the specified
GetValue()
element in the
current Array.

IndexOf() Searches for the arrVal.IndexOf(object


specified object
and returns the
index of its first
occurrence in a
one-dimensional
array or in a range
of elements in the
array.

Initializes every
element of the
value-type Array by
Initialize()
calling the default
constructor of the
value type.

Returns the index


of the last
occurrence of a
LastIndexOf() value in a one- arrVal.LastIndexOf(i)
dimensional Array
or in a portion of
the Array.

Creates a shallow
MemberwiseClone() copy of the current
Object.

Changes the Array.Resize(ref


number of elements arrVal, len-2);
of a one-
Resize() where len is the
dimensional array
to the specified original length of
new size. the array

Reverses the order


of the elements in a
Reverse() one-dimensional arrVal.Reverse()
Array or in a portion
of the Array.

Sets the specified


element in the
SetValue() Array.SetValue(arrVal
current Array to the
specified value.

Sorts the elements


Sort() in a one- Array.Sort(arrVal)
dimensional array.

Returns a string
that represents the
ToString() current object. arrVal.ToString()
(Inherited from
Object)

Determines
whether every
element in the array Array.TrueForAll(arrVa
TrueForAll() matches the <matching
conditions defined pattern>)
by the specified
predicate.

Control Statements
if (true) {...}
if-else else if (true) {...}
else {...}

switch (var)
{
case 1: break;
switch
case 2: break;
default: break;

for for (int i =0; i <=len; i++) {...}

foreach-in foreach (int item in array) {...}

while while (true) {...}

do {...}
do... while
while (true);

try {...}
catch (Exception e) {...}
try-catch-finally
catch {...}
finally {...}

Regular Expressions

+ match one or more occurrence

match any occurrence (zero or


*
more)

? match 0 or 1 occurrence

match decimal digit or non-


\d \D
character

\w \W match any word character

match white space or no white


\s \S
space

match any character inside the


[]
square brackets

match any character not


[^]
present in the square brackets

a|b either a or b

\n new line

\r carriage return
\t tab

Collections
Arraylist

Gets or sets the number of


Capacity elements that the ArrayList
can contain.

Gets the number of elements


Count actually contained in the
ArrayList.

Gets a value indicating


IsFixedSize whether the ArrayList has a
fixed size.

Returns whether the ArrayList


IsReadOnly
is read-only

Gets or sets the element at the


Item
specified index.

Adds an object to the end of


Add(object value)
the ArrayList

Adds the elements of an


AddRange(ICollection c); ICollection to the end of the
ArrayList.

Removes all elements of an


Clear();
ArrayList.

Checks whether an element is


Contains(object item);
in the ArrayList.

Returns an ArrayList which


represents a subset of the
GetRange(int index, int count);
elements in the source
ArrayList.

Returns the zero-based index


of the first occurrence of a
IndexOf(object);
value in the ArrayList or in a
portion of it.

Inserts an element into the


Insert(int index, object value); ArrayList at the specified
index.

Inserts the elements of a


InsertRange(int index,
collection into the ArrayList at
ICollection c);
the specified index.

Removes the first occurrence


Remove(object obj); of a specific object from the
ArrayList.
Removes the element at the
RemoveAt(int index); specified index of the
ArrayList.

RemoveRange(int index, int Removes a range of elements


count); from the ArrayList

Reverses the order of the


Reverse();
elements in the ArrayList.

Copies the elements of a


SetRange(int index, ICollection
collection over a range of
c);
elements in the ArrayList.

Sorts the elements in the


Sort();
ArrayList.

Sets the capacity to the actual


TrimToSize(); number of elements in the
ArrayList.

Hashtable

Gets the number of key-and-


Count value pairs contained in the
Hashtable.

Gets a value indicating


IsFixedSize whether the Hashtable has a
fixed size

Gets a value indicating


IsReadOnly whether the Hashtable is read-
only.

Gets or sets the value


Item associated with the specified
key.

Gets an ICollection containing


Keys
the keys in the Hashtable.

Gets an ICollection containing


Values
the values in the Hashtable

Adds an element with the


Add(object key, object value); specified key and value into
the Hashtable

Removes all elements from the


Clear();
Hashtable.

Determines whether the


ContainsKey(object key); Hashtable contains a specific
key.

Determines whether the


ContainsValue(object value); Hashtable contains a specific
value.
Removes the element with the
Remove(object key); specified key from the
Hashtable.

SortedList

Gets or sets the capacity of


Capacity
the SortedList.

Gets the number of elements


Count
in the SortedList.

Checks if the SortedList is of


IsFixedSize
fixed size.

Checks if the SortedList is


IsReadOnly
read-only.

Gets and sets the value


Item associated with a specific key
in the SortedList.

Gets the keys in the


Keys
SortedList.

Gets the values in the


Values
SortedList.

Adds an element with the


Add(object key, object value) specified key and value into
the SortedList.

Removes all elements from the


Clear()
SortedList.

Checks if the SortedList


ContainsKey(object key);
contains a specific key.

Checks if the SortedList


ContainsValue(object value);
contains a specific value.

Gets the value at the specified


GetByIndex(int index);
index of the SortedList.

Gets the key at the specified


GetKey(int index);
index of the SortedList.

Returns list of keys in the


GetKeyList();
SortedList

Returns list of values in the


GetValueList();
SortedList

Returns the zero-based index


IndexOfKey(object key); of the specified key in the
SortedList.

IndexOfValue(object value); Returns the zero-based index


of the first occurrence of the
specified value in the
SortedList.

Removes the element with the


Remove(object key); specified key from the
SortedList.

Removes the element at the


RemoveAt(int index);
specified index of SortedList.

Sets the capacity to the actual


TrimToSize(); number of elements in the
SortedList.

Stack

Number of elements in the


Count
Stack.

Removes all elements from the


Clear();
Stack.

Checks if an element is in the


Contains(object obj);
Stack.

Returns the object at the top


Peek(); of the Stack without removing
it.

Removes and returns the


Pop();
object at the top of the Stack.

Inserts an object at the top of


Push(object obj);
the Stack.

Copies the Stack to a new


ToArray();
array.

Queue

number of elements in the


Count
Queue.

Removes all elements from the


Clear();
Queue.

Checks if the specified object


Contains(object obj);
is present in the Queue.

Removes and returns the


Dequeue(); object at the beginning of the
Queue.

Adds an object to the end of


Enqueue(object obj);
the Queue.

Copies the Queue to a new


ToArray();
array.
Sets the capacity to the actual
TrimToSize(); number of elements in the
Queue.

Dictionary

Gets the total number of


Count elements exists in the
Dictionary<TKey,TValue>.

Returns a boolean after


checking if the
IsReadOnly
Dictionary<TKey,TValue> is
read-only.

Gets or sets the element with


Item the specified key in the
Dictionary<TKey,TValue>.

Returns collection of keys of


Keys
Dictionary<TKey,TValue>.

Returns collection of values in


Values
Dictionary<TKey,TValue>.

Add key-value pairs in


Add Dictionary<TKey, TValue>
collection.

Removes the first occurrence


Remove of specified item from the
Dictionary<TKey, TValue>.

Checks if the specified key


ContainsKey exists in Dictionary<TKey,
TValue>.

Checks if the specified value


ContainsValue exists in Dictionary<TKey,
TValue>.

Removes all the elements from


Clear
Dictionary<TKey, TValue>.

Returns true and assigns the


value with specified key, if key
TryGetValue
does not exists then return
false.

Exception Handling

try{
} catch (Exception e){
throw;
}

Methods
No return type public void MyMethod(){}

static method, no object public static void MyMethod()


needed to call method {}

public returnType MyMethod(){


with return type return val;

public void MyMethod(String


passing parameters s, int i) {

Classes

Class MyClass
{
/*Class definition*/
}
Object creation –
MyClass ClassObj = new MyClass();

Partial Class
Classes within the same namespace can be split into smaller
classes with same name.

// PartialClass1.cs // PartialClass2.cs
using System; using System;
namespace PartialClasses namespace PartialClasses
{ {
public partial class PartialCl public partial class PartialCl
{ {
public void HelloWorld() public void HelloUser()
{ {
Console.WriteLine("Hello, worl Console.WriteLine("Hello, user
} }
} }
} }

A single instance is enough to call the methods of these partial


classes.

PartialClass pc = new PartialClass();


pc.HelloWorld();
pc.HelloUser();

File Handling

Check the
existence of the file
File.Exists File.Exists(path)
in the specified
path
Read all the lines File.ReadAllLines(path
from the file
File.ReadAllLines Console.WriteLines(F
specified by the
path // Write to console

Read all the text


from the file and
File.ReadAllText File.ReadAllText(path
store it as a single
string

Copy content from File.Copy(srcfilepath,


File.Copy
one file to another destfilepath);

Delete an existing
File.Delete file from the File.Delete(path)
specified path

People are also reading:

MySQL Cheat Sheet PDF


GIT Cheat Sheet PDF
Java Cheat Sheet PDF
CSS Cheat Sheet PDF
Bootstrap Interview Questions
Bootstrap Cheat Sheet

Explore More
search... SHOW ALL

STAY IN LOOP TO BE AT THE TOP

Subscribe to
our newsletter
Enter email here

Subscribe Now

You might also like