.net framework
framework is a collection of tools and library which is used to applications development
.net environment
1) programming environment
2) web environment
3) window environment
1) programming environment
programming environment is represent console programming (c#)
2)web environment
is represent using asp.net with c#
3) window environment :local application only software
c# programming language
:programming is a seris of valid step
types of programming
there are two types of programming language
1) code based programming language
2) form base
1) code based:-depend on code(c, c++, java etc)
2) form base :- based on tools(.net framework, android studio)
programming environment
user--->compiler(1.group 2.gives syntex error)---->interpriter(1.step by step 2.gives logical error)
c#
pure object oriented programming language
2) object oriented programming is based on class and object
3) structure of c#
header--->using
class name
{
static void main()
{
all programming
}
}
4)c# provide auto statement features
how to create c# programm in .net
1) create byour own directory
2)open .net
file--->new--->project--->select visualc#---->consol application----->browse-->select directory---ok
output statement of c#
console.writeline();
ex console.writeline("welcome");
hold the output screen in c# using readkey
all purpal color is representing function we have to add ();after enntering purpal colored keyword
c#veriable
1) numerical--->int
2) decimal-->flot/double
3) string--> string
4) boolean--> boolean(true/falls)
all blue color represent data type after entering datatype we have to add(;)
*** for numerical input we have to use----> int.parse();
*** for user input we have to use----> console.readline();
task: convert all if else if programm in c#
c # function
1) what is function---notes js
2) function seperator---()---notes js
3) function parameter---notes js
how to create function in c#
1) all function is to be create befor the main body
syntex:-
type functionname()
{
}
void display()
{
console.writeline("this is my function");
}
how to access function in c#
1) all function is to be access using object
all objects is to be create inside the main body
syntex:-
classname objname=new classname();
how to access function with object
all function is to be access with object using . operator
object.functionname
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csharpfunction
{
class Program
{
//create function
void display()
{
Console.WriteLine("this is my first function programm");
}
static void Main(string[] args)
{
//classname objname=new classname();
Program p1 = new Program();
//object.functionname
p1.display();
Console.ReadKey();
}
}
}
function with parameter
namespace csharpfunction
{
class Program
{
//create function
void display(int a)
{
Console.WriteLine("this is my first function programm");
Console.WriteLine(a);
}
static void Main(string[] args)
{
//classname objname=new classname();
Program p1 = new Program();
//object.functionname
p1.display(10);
Console.ReadKey();
}
}
}
user input
namespace csharpfunction
{
class Program
{
//create function
void display(int a)
{
Console.WriteLine("this is my first function programm");
Console.WriteLine(a);
}
static void Main(string[] args)
{
int a;
Console.WriteLine("enter any number");
a = int.Parse(Console.ReadLine());
//classname objname=new classname();
Program p1 = new Program();
//object.functionname
p1.display(a);
Console.ReadKey();
}
}
}
multipal parameter
namespace csharpfunction
{
class Program
{
//create function
void display(int a, string name)
{
Console.WriteLine("this is my first function programm");
Console.WriteLine(a);
Console.WriteLine(name);
}
static void Main(string[] args)
{
int a;
string n;
Console.WriteLine("enter your name");
n = Console.ReadLine();
Console.WriteLine("enter any number");
a = int.Parse(Console.ReadLine());
//classname objname=new classname();
Program p1 = new Program();
//object.functionname
p1.display(a,n);
Console.ReadKey();
}
}
}
function within function
in function within a function concept user can use multiple function inside an another function
namespace csharpfunction
{
class Program
{
//create function
void display(int a, string name)
{
Console.WriteLine("this is my first function programm");
Console.WriteLine(a);
Console.WriteLine(name);
show();
}
void show()
{
Console.WriteLine("this is my show function");
}
static void Main(string[] args)
{
int a;
string n;
Console.WriteLine("enter your name");
n = Console.ReadLine();
Console.WriteLine("enter any number");
a = int.Parse(Console.ReadLine());
//classname objname=new classname();
Program p1 = new Program();
//object.functionname
p1.display(a,n);
Console.ReadKey();
}
}
}
task: conver all loop programm in c#
write a programm to convert function into c#
write a programm to generate following result
--create a function input accept the following parameter name. email, mobile, age, city
--check the following condition if age is greater than 18 you can vote otherwise you can not vote all parameter are given by the user
oops(object oriented programming):-
object oriented programming is based on class and object
what is class :-
class is a collection of member and methods
class name
{
member ;
method;
}
ex
class my
{
int a;-----member
console.writeline();-----method
}
rules of class:-
1) in c# main class cannot be count
2) in object oriented programming all class is to be created before the main class
3) how to access class
----all class to be access with the help of object
syntex:- classname objname=new classname
namespace classobject
{
class student
{
public void show()
{
Console.WriteLine("this is my first programm");
}
}
class Program
{
static void Main(string[] args)
{
//create object
student s1 = new student();
s1.show();
console.readkey();
}
}
}
object-----> student s1=new student();
4)all object is to be create inside the main body
5) all methods inside the class are by default private
class
{
void show()----private
}
so we have to insert public keyword befor void show()
how to use parameter in class and object
namespace classobject
{
class student
{
public void show(int a)
{
Console.WriteLine("this is my first programm");
Console.WriteLine(a);
}
}
class Program
{
static void Main(string[] args)
{
//create object
student s1 = new student();
s1.show(20);
Console.ReadKey();
}
}
}
approch of class and object ---bottom to up
how to use user input parameter in class and object
namespace classobject
{
class student
{
public void show(int a)
{
Console.WriteLine("this is my first programm");
Console.WriteLine(a);
}
}
class Program
{
static void Main(string[] args)
{
//create object
student s1 = new student();
int no;
Console.WriteLine("enter any number");
no = int.Parse(Console.ReadLine());
s1.show(no);
Console.ReadKey();
}
}
}
task ---write a programm to generate the following result
create a class employee
create a method input -- public void input()
input following parameter using input function..name city state salary --
all data input by the user check the following condition inside the input function salary greater than 5000 then display "a grade"
salary > 2000 and <5000 display b grade
otherwise display new joining
namespace assclassobject
{
class employee
{
public void input(string n, string c, string s, int sal)
{
Console.WriteLine("employee name:-"+ n);
Console.WriteLine("employee city:-" + c);
Console.WriteLine("employee state:-"+ s);
Console.WriteLine("employee salary:-"+ sal);
if(sal>=5000)
{
Console.WriteLine("A grade");
}
else if (sal>=2000 && sal<=5000)
{
Console.WriteLine("B grade");
}
else
{
Console.WriteLine("new joining");
}
}
}
class Program
{
static void Main(string[] args)
{
string na, ci, st;
int sa;
Console.WriteLine("enter your name");
na = Console.ReadLine();
Console.WriteLine("enter your city name");
ci = Console.ReadLine();
Console.WriteLine("enter your state");
st = Console.ReadLine();
Console.WriteLine("enter your salary");
sa = int.Parse(Console.ReadLine());
employee e1 = new employee();
e1.input(na,ci,st,sa);
Console.ReadKey();
}
}
}
convert all looping in class and object
write a programm to generate the following result
create a class student
create a method input public void input(name,city, age)
all parameter given by the user and check the following option
age=18---new admission
age=25---old addmission
age=30--passout
switch case
create a class student
create a method input(name, age, m1, m2, m3, m4, m5)
input all the info by user check the following condition
1) all subject mark >40 calculate total
2) check the following condition total>500 --"first div"
total>200 && <500--sec div
total>100 && <200--third div
else fail
23-02-23
C SHARP CONSTRUCTOR
1) class name and method name are similler
ex. class a
{
public void a ()
{
}
}
a a1=new a
2) constructor cannot use void keyword
3) constructor function cannot use private specifire
4) constructor function automatically access when object is created
namespace constructor
{
class one
{
public one()
{
Console.WriteLine("this is constructor method");
}
}
class Program
{
static void Main(string[] args)
{
one a1 = new one();
Console.ReadKey();
}
}
}
PARAMETERISED CONSTRUCTOR
namespace constructor
{
class one
{
public one(int a)
{
Console.WriteLine("this is constructor method");
Console.WriteLine(a);
}
}
class Program
{
static void Main(string[] args)
{
one a1 = new one(10);
Console.ReadKey();
}
}
}
PARAMETERISED CONSTRUCTOR with user input
namespace constructor
{
class one
{
public one(int a)
{
Console.WriteLine("this is constructor method");
Console.WriteLine(a);
}
}
class Program
{
static void Main(string[] args)
{
int n;
Console.WriteLine("enter any number");
n = int.Parse(Console.ReadLine());
one a1 = new one(n);
Console.ReadKey();
}
}
}
****INHERRITANCE****
1)inherritance is communication between multiple classes
2)inherritance is reusibility of the class
3)there are two types of classes base class and derived class
base class:-all previous class is called base class
derived class:- all next class is called derived class
4) main class cannot be count in inherritance
5) in inherritance create last class object
6)c sharp cannot support multiple in herritance
ex. class a
class b:a
class c:b
class d:a:b:c---cannot support
namespace inherritance
{
class a
{
public void display()
{
Console.WriteLine("this is inherritance programm and this is fist class message");
}
}
class b:a
//this is inherritance
{
public void show()
{
Console.WriteLine("this is second class");
}
}
class c:b
{
public void print()
{
Console.WriteLine("this is third class");
}
}
class Program
{
static void Main(string[] args)
{
c c1 = new c();
c1.display();
c1.show();
c1.print();
Console.ReadKey();
}
}
}
TASK
CREATE A PROGRAMM IN FOLLOWING RESULT
create a class student
create a constructor with following parametor (name, city, college, percentage)
create a method--public void display()
display all the information from this function
create a method --public void gread()
check the following condition
per>60 first div
per>50 && <60 second div
per >40 && <50 third div otherwise fail
all parametor given by the user
logic:-
class student
{
string n1,c1,co1;
int per1;
public student(string name, city, college, int per)
{
n1=name;
c1=city;
co1=college;
per1=per;
}
public void display()
{
console.writeline(n1);
-
--
}
public void gread()
{
if(per1>60)
{
console.writeline("a gread");
}
}
}
in gread function create a parametor in gread function
and check the condition
task 2 inherritance
create a class employee
create a method public void input() accept the following parametor
name city sallary designation
create an other class info
create a method public void display() display all the information of employee
create an other class remark
create a method public void output() check the following condition
salary >5000 a grade
salary >2000 && <5000 b grade
salary >1000 && <2000 c grade
otherwise no gread
all parametor given by the user
namespace assinheritance
{
class employee
{
public string n, c, d;
public int s;
public void input(string name, string city, int salary, string des)
{
n = name;
c = city;
s = salary;
d = des;
}
}
class info:employee
{
public void display()
{
Console.WriteLine(n);
Console.WriteLine(c);
Console.WriteLine(d);
Console.WriteLine(s);
}
}
class remark:info
{
public void output(int s)
{
if (s >= 5000)
{
Console.WriteLine("A grade");
}
else if(s>=4000 && s<=5000)
{
Console.WriteLine("B grade");
}
else if (s >= 3000 && s <= 4000)
{
Console.WriteLine("C grade");
}
else
{
Console.WriteLine("no grade");
}
}
}
class Program
{
static void Main(string[] args)
{
string n, c, des;
int sal;
Console.WriteLine("enter your name here");
n = Console.ReadLine();
Console.WriteLine("enter your city");
c = Console.ReadLine();
Console.WriteLine("enter your designation");
des = Console.ReadLine();
Console.WriteLine("enter your salary");
sal = int.Parse(Console.ReadLine());
remark r1 = new remark();
r1.input(n,c,sal,des);
r1.output(sal);
r1.display();
Console.ReadKey();
}
}
}
***hint..another way to print parameter from one class to second class.. create object of first class in second
employee e1=new employee();
e1.output();
task 3
implimentation of constructor in inheritance
namespace assinheritconstructor
{
class student
{
public student()
{
Console.WriteLine("this is demo programm for constructor in inheritance this is message from base class student");
}
}
class display:student
{
public display()
{
Console.WriteLine("this is child class message from child class display");
}
}
class Program
{
static void Main(string[] args)
{
display d1 = new display();
Console.ReadKey();
}
}
}
CLASS SECURITY
in class security we have to use two specific concept
1) abstract class
2) sealed class
abstract class :- abstract class is provide two specific properti
* abstract class cannot create a object
*abstract class only inherit to an other class
* all class is to be create abstract class with the help of abstract keyword
syntex:-
abstract class name;
namespace classsecurity
{
abstract class student
{
public void display()
{
Console.WriteLine("this is to check abstract class");
}
}
class college:student
{
public void show()
{
Console.WriteLine("this is second class to check abstract rule");
}
}
class Program
{
static void Main(string[] args)
{
college s1 = new college();
s1.display();
s1.show();
Console.ReadKey();
}
}
}
sealed class : it provide two properties
* sealed class cannot inherit
* sealed class direct create object
* sealed class is to be create using sealed keyword
namespace classsecuritysealed
{
sealed class student
{
public void display()
{
Console.WriteLine("this is my first class");
}
}
class college
{
public void show()
{
Console.WriteLine("this is second class");
}
}
class Program
{
static void Main(string[] args)
{
student s1 = new student();
college c1 = new college();
s1.display();
c1.show();
Console.ReadKey();
}
}
}
INTERFACE
1) interface is provide the implimentation of multiple inheritance
2) interface is the part of abstraction
3) interface is to be create with the help of interface keyword
syntex:-
interface name
{
}
inside the interface function only declare
{void show()}
inside the interface function cannot use public specifire {public void show()} not possible
all interface is to be access inside the class using : operator
all interface function is to be created inside the class
C SHARP CANNOT MULTIPLE INHERITANCE IF WE WANT TO DO THE SAME USE INTERFACE
TASK
1) inheritance with constructor with parameter
namespace assinherconstructpara
{
class student
{
public string n, col, c;
public int a;
public student(string name,string college,string city, int age )
{
n = name;
col = college;
c = city;
a = age;
}
}
class display : student
{
public display ()
{
Console.WriteLine(n);
Console.WriteLine(col);
Console.WriteLine(c);
Console.WriteLine(a);
}
}
class Program
{
static void Main(string[] args)
{
display d1 = new display();
Console.ReadKey();
}
}
}
2) write a programm to generate following result
create a interface ---college
declare a function input
interface college
{
void input(string );
}
accept the following parameter name city state contry age
create an othe interface admission
interface admission
{
void output();
}
diclare function output
create class student and implementation all the interface inside the class and display all the information using output function
all parameter given by the user
check the followin g condition
if age >=20 the display new admission othewise display weit for new session
namespace assinterface
{
interface college
{
void input(string name, string city, string state, string contry, int age);
}
interface admission
{
void output();
}
class student:college,admission
{
public string n, c, s, co;
public int a;
public void input(string name, string city, string state, string contry, int age)
{
n = name;
c = city;
s = state;
co = contry;
a = age;
}
public void output()
{
Console.WriteLine(n);
Console.WriteLine(c);
Console.WriteLine(s);
Console.WriteLine(co);
Console.WriteLine(a);
if (a >= 20)
{
Console.WriteLine("new admission");
}
else
{
Console.WriteLine("wait for new session");
}
}
}
class Program
{
static void Main(string[] args)
{
string n1, c1, s1, co1;
int a1;
Console.WriteLine("enter your name");
n1 = Console.ReadLine();
Console.WriteLine("enter your city");
c1 = Console.ReadLine();
Console.WriteLine("enter your state");
s1 = Console.ReadLine();
Console.WriteLine("enter your college name");
co1 = Console.ReadLine();
Console.WriteLine("enter your age");
a1 =int.Parse(Console.ReadLine());
student s2 = new student();
s2.input(n1,c1,s1,co1,a1);
s2.output();
Console.ReadKey();
}
}
}
write a programm to impliment interface with inheritance
namespace interfacewithinheritance
{
interface one
{
void input(string name);
}
class student : one
{
public string n;
public void input(string name)
{
n = name;
}
}
class study : student
{
public void input(string n)
{
Console.WriteLine("my name is:-"+n);
}
}
class Program
{
static void Main(string[] args)
{
string n;
Console.WriteLine("enter your name");
n = Console.ReadLine();
study s1 = new study();
s1.input(n);
Console.ReadKey();
}
}
}
C SHARP STRUCTURE
1) Structure is a collection of diffrent data element
structure is used to create struct keyword
structure is used to create before the main body
there is no need to create function .ie public void ()
ex a= 1,a,3,i,b;
all member inside the structure called public
syntex
struct name
{
member;
}
how to access stucture member
all structure member is to be access using structure object
syntex
structurename objname;
student s1;
all object is to be create inside the main body
namespace @struct
{
struct student
{
public string name;
public int roll;
}
//how to access stucture member all structure member is to be access using structure object
class Program
{
static void Main(string[] args)
{
student s1;
Console.WriteLine("enter your name");
s1.name = Console.ReadLine();
Console.WriteLine("enter your roll no");
s1.roll = int.Parse(Console.ReadLine());
Console.WriteLine(s1.name+"-"+s1.roll);
Console.ReadKey();
}
}
}
TASK
WRITE A PROGRAMM TO GENERATE FOLLOWING RESULT
create a structure employee
there are following member in a structure (name, city, age, salary)
create a class company
create a method display()
all structure member is to be display using display method
all structure member input by the user
namespace assstructure
{
//WRITE A PROGRAMM TO GENERATE FOLLOWING RESULT
//create a structure employee there are following member in a structure (name, city, age, salary)
//create a class company create a method display()all structure member is to be display using display method all structure member input by the user
struct employee
{
public string name, city;
public int age, salary;
}
class company
{
public void display(string n, string c, int a, int sal)
{
Console.WriteLine(n);
Console.WriteLine(c);
Console.WriteLine(a);
Console.WriteLine(sal);
}
}
class Program
{
static void Main(string[] args)
{
employee e1;
Console.WriteLine("enter your name");
e1.name = Console.ReadLine();
Console.WriteLine("enter your city");
e1.city = Console.ReadLine();
Console.WriteLine("enter your age");
e1.age = int.Parse(Console.ReadLine());
Console.WriteLine("enter your salary");
e1.salary = int.Parse(Console.ReadLine());
company c1 = new company();
c1.display(e1.name, e1.city, e1.age, e1.salary);
Console.ReadKey();
}
}
}
ARRAY
array is collection of similar type data element
ARRAY SEPARATER--- [ ]
HOW TO CREATE ARRAY
syntex
data type[]arrayname=new datatype[size];
ex. int[]a=new int[5]
array start from zero value which is also called index value
METHOD FOR DATA STOREAGE IN ARRAY
1) USING SUBSCRIPT METHOD
2) USING USER INPUT METHOD
SUBSCRIPT METHOD
namespace ARRAY
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[5];
//here 5 is called subscript element
a[0] = 10;
a[1] = 20;
a[2] = 30;
a[3] = 40;
a[4] = 50;
Console.WriteLine(a[0]);
Console.WriteLine(a[1]);
Console.WriteLine(a[2]);
Console.WriteLine(a[3]);
Console.WriteLine(a[4]);
Console.ReadKey();
}
}
}
for large array there is no need to give command number of times the problem is solve using loop method for loop
1) input loop
2) output loop
input loop
--amespace arraywloop
{
class Program
{
static void Main(string[] args)
{
int[]a=new int[5];
int i;
for (i = 0; i < 5; i++)
{
Console.WriteLine("enter any number");
a[i] = int.Parse(Console.ReadLine());
}
for (i = 0; i < 5; i++)
{
Console.WriteLine(a[i]);
}
Console.ReadKey();
}
}
}
TASK
1) display sum of array element
namespace assarrayadd
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[5];
int n;
for (n = 0; n < 5; n++)
{
Console.WriteLine("enter any number");
a[n] = int.Parse(Console.ReadLine());
}
for (n = 0; n < 1; n++)
{
Console.WriteLine(a[0]+ a[1]+ a[2]+a[3]+a[4]);
}
Console.ReadKey();
}
}
}
2) >number of array element
namespace assarraygreat
{
class Program
{
static void Main(string[] args)
{
int[]a=new int[5];
int i;
int great;
for (i = 0; i < 5; i++)
{
Console.WriteLine("enter any number");
a[i]= int.Parse(Console.ReadLine());
}
great = a[0];
for (i = 0; i < 5; i++)
{
if (great < a[i])
great = a[i];
}
Console.WriteLine("largest element in array is:-"+ great);
Console.ReadKey();
}
}
}
3) <number of array element
namespace assarraysmallno
{
class Program
{
static void Main(string[] args)
{
int[]a=new int[5];
int i;
int small;
for (i = 0; i < 5; i++)
{
Console.WriteLine("enter any number");
a[i]= int.Parse(Console.ReadLine());
}
small = a[0];
for (i = 0; i < 5; i++)
{
if (small > a[i])
small = a[i];
}
Console.WriteLine("smallest element in array is:-"+ small);
Console.ReadKey();
}
}
}
4) even number of array element
namespace assarrayeven
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[5];
int i;
for (i = 0; i < 5; i++)
{
Console.WriteLine("enter any number");
a[i] = int.Parse(Console.ReadLine());
}
for (i = 0; i < 5; i++)
{
if (a[i] % 2 ==0)
Console.WriteLine(a[i]);
}
Console.ReadKey();
}
}
}
5) odd number of array element
namespace assarrayodd
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[5];
int i;
for (i = 0; i < 5; i++)
{
Console.WriteLine("enter any number");
a[i] = int.Parse(Console.ReadLine());
}
for (i = 0; i < 5; i++)
{
if (a[i] % 2 != 0)
Console.WriteLine(a[i]);
}
Console.ReadKey();
}
}
}
6)create string array in 5 element
namespace assarraystring
{
class Program
{
static void Main(string[] args)
{
string[] a = new string[5];
int n;
for (n = 0; n < 5; n++)
{
Console.WriteLine("enter any name");
a[n] = Console.ReadLine();
}
for (n = 0; n < 5; n++)
{
Console.WriteLine(a[n]);
}
Console.ReadKey();
}
}
}
dt 02-03-23
C# NAMESPACE
1) namespace is a collection of class
2) namespace is to be create namespace keyword
syntex
namespace name
{
classes
}
namespace student
{
class one
{
}
class two
{
}
}
how to create namespace object
---namespace nspace
{
namespace student
{
class one
{
public void display()
{
Console.WriteLine("this is my first namespace programm");
}
}
class two
{
public void show()
{
Console.WriteLine("this is my second class of namespace programm");
}
}
}
class Program
{
static void Main(string[] args)
{
//syntex
//namespace.classname obj=new namespace.classname();
student.one o1 = new student.one();
student.two o2 = new student.two();
o1.display();
o2.show();
Console.ReadKey();
}
}
}
TASK :- ANY ONE IMPLIMENTATION NAMESPACE WITH PARAMETER
//ANY ONE IMPLIMENTATION NAMESPACE WITH PARAMETER// create a class employee
//create a method public void input() accept the following parametor
//name city sallary designation display all the information of employee create an other class info
//create a method public void display() dispay if salary<20000 promotion otherwise wait for next 6 month
namespace assnamespace
{
namespace company
{
class employee
{
public string n, c, d;
public int s;
public void input(string name, string city, string designation, int sallary)
{
n = name;
c = city;
d = designation;
s = sallary;
Console.WriteLine(n);
Console.WriteLine(c);
Console.WriteLine(d);
Console.WriteLine(s);
}
}
class info
{
public void display(int sal)
{
if (sal < 20000)
{
Console.WriteLine("you are promoted");
}
else
{
Console.WriteLine("wait for next 6 month");
}
}
}
}
class Program
{
static void Main(string[] args)
{string n1,c1,d1;
int s1;
Console.WriteLine("write your name");
n1 = Console.ReadLine();
Console.WriteLine("write your city name");
c1 = Console.ReadLine();
Console.WriteLine("write your designation");
d1 = Console.ReadLine();
Console.WriteLine("write your sallary");
s1 =int.Parse( Console.ReadLine());
company.employee e1 = new company.employee();
company.info i1 = new company.info();
e1.input(n1,c1,d1,s1);
i1.display(s1);
Console.ReadKey();
}
}
}
C SHARP COLLECTION
1) collection is special type of class is used to group of data concept
2) in collection all data is to be manage index location
3) all collection is use to collection library ---using system.collection
TYPES OF COLLECTION
1) Arraylist
2)hash table
3) stack
1) arraylist is a collection which is store all types of data element in index position
::in array
for loop is used to variable looping
while in ::arraylist
foreach loop is used to object looping
cannot use < > in foreach loop
array
int[]a----variable=new[];
arraylist
arraylist a----object=new arraylist();
namespace collectionarraylist
{
class Program
{
static void Main(string[] args)
{
//create arraylist
ArrayList a1 = new ArrayList();
//how to insert data in arraylist
a1.Add(50);
a1.Add(30);
a1.Add(10);
a1.Add(3);
a1.Add(5);
//how to display number of count in arraylist
Console.WriteLine(a1.Count);
//how to desplay arraylist element
foreach (int i in a1)
{
Console.WriteLine(i);
}
//how to arrange arraylist element ---using sort();
a1.Sort();
Console.WriteLine("display aaraylist data element after sorting");
foreach (int j in a1)
{
Console.WriteLine(j);
}
Console.ReadKey();
}
}
}
TASK:-INPUT 5 ELEMENT BY THE USER IN ARRAYLIST AND PERFORM THE SORT OPERATION
namespace asscollectionarraylist
{//INPUT 5 ELEMENT BY THE USER IN ARRAYLIST AND PERFORM THE SORT OPERATION
class Program
{
static void Main(string[] args)
{
ArrayList a1 = new ArrayList();
int a, b, c, d, e;
Console.WriteLine("enter any number");
a = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
b = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
c = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
d = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
e = int.Parse(Console.ReadLine());
a1.Add(a);
a1.Add(b);
a1.Add(c);
a1.Add(d);
a1.Add(e);
foreach (int i in a1)
{
Console.WriteLine(i);
}
a1.Sort();
Console.WriteLine("display arraylist element after sorting");
foreach (int f in a1)
{
Console.WriteLine(f);
}
Console.ReadKey();
}
}
}
***STACK
1) Stack is use to arranging data element in LIFO PATTERN last in first out
2) using push () ; function to store data in a stack
3) remove stack element using pop (); function
4) there is no sort() function use in stack
namespace collectionstack
{
class Program
{
static void Main(string[] args)
{
Stack s1 = new Stack();
//insert stack element using push();
s1.Push('A');
s1.Push('B');
s1.Push('C');
s1.Push('D');
//display data element foreach loop
foreach (char s in s1)
{
Console.WriteLine(s);
}
s1.Pop();
Console.WriteLine("remove stack");
foreach (char c in s1)
{
Console.WriteLine(c);
}
Console.ReadKey();
}
}
}
TASK
STACK IN USER INPUT
namespace asscollectionstack1
{
class Program
{
static void Main(string[] args)
{
Stack s1 = new Stack();
int a, b, c, d, e;
Console.WriteLine("enter any number");
a = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
b = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
c = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
d = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
e = int.Parse(Console.ReadLine());
s1.Push(a);
s1.Push(b);
s1.Push(c);
s1.Push(d);
s1.Push(e);
foreach (int i in s1)
{
Console.WriteLine(i);
}
s1.Pop();
Console.WriteLine("display numbers after pop process");
foreach (int f in s1)
{
Console.WriteLine(f);
}
Console.ReadKey();
}
}
}
****unsuccessfull
ENTER 5 CHARECTER IN STACK USER INPUT , HOW MANY ELEMENT DELETE USER INPUT?
namespace asscollectionstack3
{//ENTER 5 CHARECTER IN STACK USER INPUT , HOW MANY ELEMENT DELETE USER INPUT?
class Program
{
static void Main(string[] args)
{
Stack s1 = new Stack();
int a, b, c, d, e;
Console.WriteLine("enter any number");
a = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
b = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
c = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
d = int.Parse(Console.ReadLine());
Console.WriteLine("enter any number");
e = int.Parse(Console.ReadLine());
s1.Push(a);
s1.Push(b);
s1.Push(c);
s1.Push(d);
s1.Push(e);
foreach (int i in s1)
{
Console.WriteLine(i);
}
int del;
Console.WriteLine("enter any number 1 to 5 to remove numbers of element from the stack");
del = int.Parse(Console.ReadLine());
switch (del)
{
case 1: s1.Pop();
break;
case 2: s1.Pop(); s1.Pop();
break;
case 3: s1.Pop(); s1.Pop(); s1.Pop();
break;
default: Console.WriteLine("invalid");
break;
}
Console.WriteLine("display numbers after pop process");
foreach (int f in s1)
{
Console.WriteLine(f);
}
Console.ReadKey();
}
}
}
04-03-2023
HASH TABLE
1)Hash table is an other type of collection is used to store data in perticular index
nagpur--001
puna--002
namespace collectionhashtable
{
class Program
{
static void Main(string[] args)
{
Hashtable h1 = new Hashtable();
h1.Add("001", "nagpur");
h1.Add("002", "puna");
h1.Add("003", "mumbai");
h1.Add("004", "hyderabad");
h1.Add("005", "delhi");
foreach (string i in h1.Keys)
{
Console.WriteLine(i+ " "+ h1[i]);
}
Console.ReadKey();
}
}
}
****EXCEPTION HANDLING:-
1) Exception handling is representing logical error concept
2) in c# provide some types of exception handling concept
1) trycatch 2) finally
***trycatch:- it is exception handling statement
try logic creation catch - returning logical error
syntex:-
try
{
programm/logic creation
}
catch(exception e)
{
returning the logical error
}
namespace exceptiontrycatch
{
class Program
{
static void Main(string[] args)
{
try
{
int a=10,b=0,c;
c = a / b;
Console.WriteLine(c);
}
catch(Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
}
}
***finally:- finally is use to represent specific comment by the user
which is writen after try catch method
namespace exceptiontrycatch
{
class Program
{
static void Main(string[] args)
{
try
{
int a = 10, b = 0, c;
c = a / b;
Console.WriteLine(c);
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
Console.WriteLine("there is an arithmatic error in the programm");
}
Console.ReadKey();
}
}
}
TASK
1) CREATE ANY FIVE PROGRAMM TO IMPLIMENT LOGICAL ERROR
namespace assexceptiontrycatch1
{
class Program
{
static void Main(string[] args)
{
try
{
Hashtable h1 = new Hashtable();
h1.Add("001", "nagpur");
h1.Add("002", "puna");
h1.Add("002", "mumbai");
h1.Add("004", "hyderabad");
h1.Add("005", "delhi");
foreach (string i in h1.Keys)
{
Console.WriteLine(i + " " + h1[i]);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
}
}
namespace assexceptiontrycatch2
{
class Program
{
static void Main(string[] args)
{
try
{
int a = 1, b = 1, c;
c = (a + b)/(a - b);
Console.WriteLine(c);
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
namespace assexceptiontrycatch3
{
class Program
{
static void Main(string[] args)
{
try
{
int[] a = new int[5];
int i=10;
for(i=0; i<6; i++)
{
Console.WriteLine(a[i]);
}
}
catch(Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
}
}
namespace assexceptiontrycatch4
{
class Program
{
static void Main(string[] args)
{
try
{
int[] a = new int[5];
a[0] = 10;
a[1] = 20;
a[2] = 30;
a[3] = 40;
a[4] = 50;
a[5] = 60;
Console.WriteLine(a[0]);
Console.WriteLine(a[1]);
Console.WriteLine(a[2]);
Console.WriteLine(a[3]);
Console.WriteLine(a[4]);
Console.WriteLine(a[5]);
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
}
}
namespace assexceptiontrycatch5
{
class Program
{
static void Main(string[] args)
{
try
{
int [] a= {1,2,3,4,5};
{
Console.WriteLine(a[6]);
}
}
catch (Exception e)
{
Console.WriteLine(e);
Console.ReadKey();
}
}
}
}
namespace assexceptiontrycatch6
{
class Program
{
static void Main(string[] args)
{
try
{
int[] a = new int[5];
int n;
for (n = 0; n < 5; n++)
{
Console.WriteLine("enter any number");
a[n] = int.Parse(Console.ReadLine());
}
for (n = 0; n < 1; n++)
{
Console.WriteLine(a[1] + a[2] + a[3] + a[4] + a[5]);
}
}
catch(Exception e )
{
Console.WriteLine(e);
}
Console.ReadKey();
}
}
}
2) HASH TABLE BY USER INPUT
namespace asshashtable
{
class Program
{
static void Main(string[] args)
{
Hashtable h1 = new Hashtable();
int a, b, c, d,e;
Console.WriteLine("enter 1-5 numbers");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = int.Parse(Console.ReadLine());
d = int.Parse(Console.ReadLine());
e = int.Parse(Console.ReadLine());
h1.Add(a,"nagpur");
h1.Add(b, "puna");
h1.Add(c, "mumbai");
h1.Add(d, "raipur");
h1.Add(e, "udaypur");
foreach (int i in h1.Keys)
{
Console.WriteLine(i+" " +h1[i]);
}
Console.ReadKey();
}
}
}
c#advance interview questions
****POLYMORPHISUM
1)polymorphisum is a object oriented programming
2) in polymorphisum create simmilar function /method for multiple classess
3) in polymorphisum base class member function (top class) is vertual (vertual keyword)
4) in polymorphisum all derived class member function is override (override keyword)
how to create object in polymorphisum
5) in polymorphisum all class is to be access base class all derive class inherit base class
there are some object is to be create in polymorphisum
1) base class object
2) derive class object using base class
//04-03-23
namespace polymorph
{
class one
{
public virtual void display()
{
Console.WriteLine("this is first function");
}
}
class two:one
{
public override void display()
{
Console.WriteLine("this is second function");
}
}
class three:one
{
public override void display()
{
Console.WriteLine("this is third function");
}
}
class Program
{
static void Main(string[] args)
{
one o1 = new one();
one o2 = new two();
one o3 = new three();
o1.display();
o2.display();
o3.display();
Console.ReadKey();
}
}
}
No comments:
Post a Comment