0% found this document useful (0 votes)
8 views140 pages

C# Exception Handling and Variable Types

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views140 pages

C# Exception Handling and Variable Types

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Exception Handling and Types of exceptions.

A finally block, in the context of C#,


refers to a block of statements that are always
executed, regardless of unexpected events or
exceptions that may occur during an
application's execution. It is used optionally
What with the "try/catch" block and guarantees the
execution of any code that must be executed
Does before exiting the "try" block, regardless of the
success or failure of the application's
Finally execution.

Block The execution of a finally block is


intended to release resources, such as
Mean? database connections, which are usually
available in limited quantities. By this
mechanism, the disposal of resources occurs
earlier than the garbage collector's finalization
operation, thereby optimizing memory.
Understanding the Static and Non-
static Variables in C#
• Whenever we declare a variable by using the static modifier in C# or when we declare a variable
inside of any static block then those variables are considered as static variables whereas the rest
of the others are considered as non-static variables.

• If you want a variable to have the same value throughout all instances of a class, then you need to
declare that variable as a static variable. So, the static variables are going to hold the application-
level data which is going to be the same for all the objects. Have a look at the following example.

Static and non-static members in C#

• The static variable gets initialized immediately once the execution of the class starts whereas the
non-static variables are initialized only after creating the object of the class and that is too for
each time the object of the class is created.
Functions Methods
Functions have independent existence means they can be Methods do not have independent existence they are always
defined outside of the class. Ex:- main() function in C, C++ defined within a class. Ex:- main() method in C# Language that
Language is defined within a class

Functions are defined in structured languages like Pascal, C and Methods are defined in object-oriented languages like C#, Java
object-based language like javaScript
Methods are called using instance or object.
Functions are called independently.
Methods are used to a manipulate the instance variable of a
Functions are a self-describing unit of code. class.

//function main in C //method sum in C#


void main() class demo
{ {
int a,b,c; int a,b,c;
a=5; public void sum()
b=6; {
c=a+b; a=5;
printf("Sum is : %d",c); b=6;
} c=a+b;
[Link]("Sum is : {0}",c);
}
}

You might also like