0% found this document useful (0 votes)
3 views14 pages

Object Oriented Application

C# is a modern object-oriented programming language developed by Microsoft, with roots in the C family and running on the .NET framework. Key features of C# include encapsulation, inheritance, and polymorphism, which facilitate the creation of robust applications. The document also covers concepts such as data types, method overloading, and ADO.NET for database interaction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views14 pages

Object Oriented Application

C# is a modern object-oriented programming language developed by Microsoft, with roots in the C family and running on the .NET framework. Key features of C# include encapsulation, inheritance, and polymorphism, which facilitate the creation of robust applications. The document also covers concepts such as data types, method overloading, and ADO.NET for database interaction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

C#

C# is a modern, general purpose, object oriented programming language


developed by Microsoft and approved by ECMA and ISO.
ECMA = European Computer
Manufactures Association

ISO= International Standards


Organizations
It was developed by Anders Hejlsberg in 1999
It has roots in the C family,It runs on the .NET framework, NET=Net Enabled Technologies

.NET framework is an integral window component that supports multiple programming


languages
.NET framework consists of of CLR =Common Language Runtime , This CLR was used to covert
high level language to low level language.

OBJECT: An Object is an Entity that has Properties for identifying its State and for Validation,
Method for Behavior/Functionality and

Events for Depicting the Change of State.

Object Oriented Application: It’s a collection of related objects, communicating with each other,
exchanging messages with other in a controlled environment as per the rules of the business.

Every object oriented language should have 3 features:

1) Encapsulation
2) Inheritance
3) Polymorphism

Encapsulation: The Process of binding data and behavior i,e Functionality of an


object within a secured and controlled environment is called as Encapsulation.
 It keeps the data safe from the outside code.
 This encapsulation principle is used to implement the information hiding i,e
DATA ABSTRACTION.
 The Process of exposing the essential data of an object to the outside of
the world and hiding the low level data of that object is called data
abstraction

Inheritance: The process of acquiring the existing functionality of the parent and
with new added features and functionality by a child object is called Inheritance.
 Using Inheritance redundant programs, programming codes can be
eliminated and the use of previously defined classes may be continued.
 Inheritance decreases coding part of the programmer.
 The advantages of Inheritance are Generalization, Extensibility and
reusability.

POLYMORPHISM:

// See https://aka.ms/new-console-template for more information


Console.WriteLine("Hello, World!");
float f = 123.4f;
Console.WriteLine(f);
double d = 23;
Console.WriteLine(d);
char C = 'D';

Console.WriteLine(C);
long verylong = 99999;
Console.WriteLine(verylong);
string st = "Anoj";Console.WriteLine(st);
Console.WriteLine("The st value is");
Write(); WriteLine():
Write() prints text without a new line. WriteLine() moves to the next line
after Printing

Console.WriteLine("The c value is {Z}");

// This is a Single-line comment, This


comment we give At the beginning or end of
the line..
/* This is a multi-line comment */
1) If we assign a new value to an existing variable in
c# then that will Overwrite the previous value ( =
is used to to assign value)
2) Dll dynamic link library that’s mean we cant read

// See https://aka.ms/new-console-template for more information

Console.WriteLine("Hello, World!");
int a = 30;
int b = 20;
int result = 0;
result = a + b;
Console.WriteLine(result);
result = a - b;
Console.WriteLine(result);
result = a/b;
Console.WriteLine(result);
result = a * b;
Console.WriteLine(result);
result = a % b;
Console.WriteLine(result);
Console.ReadKey();
string name = "prashanth";
string hisname = a+ name;
Console.WriteLine(hisname);

Decimal x = 1.2M;
Console.WriteLine(x);

We cant be do both int and string operation except one i’e +


operator;
These also called value operator;

namespace HelloWorld
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
MYLIBPRACTICE:
SOLUTION EXPLORER
CONTEXT
ADD
NEW
NEW PROJECT

Access modifier- class keyword—class name


Public class class1

Namespace-- is collection of classes

How to create a libraries


STEPS TO CREATE LIBRARY

1)CLICK ON CREATE ON NEW PROJECT

2)CLICK ON CONSOLE—OK---GIVE PROJECT NAME

LIKE MYLIBPRACTICE1-- CREATE

3) IN VISUAL STD WINDOW GOTO SOLUTION EXPLORER

THEN RIGHT CLICK ON SOLTION MYLIBPRACTICE

4) THEN CLICK ON ADD

5)CLICK ON NEW PROJECT – GIVE PROJEVCT NAME LIKE MYPROJECT1

THERE IN SOLUTION EXPLORER WE WILL SEE CLASS.1 and namespace visual window

Create variables here… then save it.

6) GOTO SOLUTION EXPLORER THEN RIGHT CLICK ON MYPROJECT

THEN CLICK ON ADD THEN CLICK ON PROJECT REFERENCE

8) HERE YOU WILL SEE PROGRAMM .C WINDOW WERE YOU WILL UPDATE LIBRARIES

BY SAY USING
Class.cs
namespace MYPROJECT4
{
public class Class1
{
public long a = 10000;
public long b = 11000;
}
}

Program.cs

Using Myproject1:
using MYPROJECT4;
Class1 objclass1 = new Class1();

Console.WriteLine(objclass1.a);
Console.WriteLine(objclass1.b);

()--- default constructor

public class Class1


{
// global variables
public int a = 20;
public int b = 30;

// default parameterless contructor


public Class1()
{
a = 40;
b = 50;

}
//methods
public void Add()
{
int d = 10;
int e = 20;
int result = 0;
result= d+ e;
Console.WriteLine(result);

}
}
Parametrised method()

public void RaviAdd(int a,int b)


{

int result = 0;
result = a + b;
Console.WriteLine(result);,

using PARAMMETHODLIBRARY;
Class1 objclass1 = new Class1();
objclass1.RaviAdd(10, 20);

namespace METHODWITH_WRITTEN
{
public class Class1
{
public int a = 1000;
public int b = 2000;

public Class1()
{
a = 300;
b = 200;
}
public void Subtract()
{
int d = 20;
int e = 10;
int result = 0;
result = d - e;
Console.WriteLine(result);

}
public void RaviSubtract(int a, int b)
{
int result = 0;
result = a - b;
Console.WriteLine(result);

}
public int Subtractwritten()
{
int d = 20;
int e = 10;
int result = 0;
result = d - e;
return result;

}
public int Subtractwtparartn(int d,int e)
{

int result = 0;
result = d - e;
return result;

}
}

using METHODWITH_WRITTEN;
Class1 objclass1 = new Class1();
int result = 0;

// calling methods

result = objclass1.Subtractwritten();
Console.WriteLine(result);

int result1 = 0;
result1 = objclass1.Subtractwtparartn(10,5);
Console.WriteLine(result1);

Go through what is polymorphism,


Inheritence
It will reduce the burden
##Parent class:
namespace InheretenceLibrary
{
public class Parent
{
public string ParentName = "Shankar";
public void GetFee()
{
Console.WriteLine("This is Parent Fees");

}
}
}
## child class
namespace InheretenceLibrary
{
public class Child : Parent
{

}
}

## objclass:
using InheretenceLibrary;
Child objchild = new Child();

objchild.GetFee();

1) inheritance allows multiple classes


2)interface contain methods defination by default.
3)the methods in interface by default can give public
modifier;
Will implement the interface in the inheritance class

Category—public void getCategoryAdd


High categoruy
Interface

Child.cs

namespace INHERITENCELIBRARYM
{
public class Child : Parent, Interface1
{
public void Add()
{
throw new NotImplementedException();
}

public void Division()


{
throw new NotImplementedException();
}

public void Multiply()


{
throw new NotImplementedException();
}

public void Subtraction()


{
throw new NotImplementedException();
}
}
}
Interface:
namespace INHERITENCELIBRARYM
{
public interface Interface1
{
public void Add();
public void Subtraction();
public void Division();
void Multiply();

}
}

namespace InheritenceLibraryMultiple
{
public class Parent
{
public virtual void AllEmployeesSalary()
{

Console.WriteLine("This is Company Salary");


}
}

public class Child : Parent


{
public override void AllEmployeesSalary()
{

Console.WriteLine("This is Child Salary");


}

public class Brother : Parent


{

}
Abstract Class: Initially it is a Base Class because,
We cannot create an object for Abstract class. But Abstract class
is accessed through inheritance.
A method without any method body is known as an Abstract
method.
Abstract class contain:1) Abstract methods
2) Non Abstract methods
-In abstract class Override is mandatory, whereas in method
Overriding it is an optional

Namespace:A namespace is used to organize your code and is


collection of Classes,Namespaces,interfaces,structs,enums and
delegates.
It is main method and entry point into your application.
Ex; using system.

Variables are containers for storing data values.


Datatypes: IT specifies the size and type of variable values.
Ex: int ,long, char, string, float, double, bool.

Data type Conversions:


1) Implicit – when there is no loss of data

EX: int I=11;


Float f =I;
o/p :11
2) Explicit Conversion: when converting a float we loose the
fractional part and it throughs an exception
EX: float f1 = 473.59f;
Int I = (int)f1;
o/p : 473

public abstract void abstractlearn


{
Public abstract Add();
{
Console.Writeline(“ add methopd”);
}
public abstract void Substraction();
}

Method override: It is also called as runtime polymorphism and


late binding
It has two keywords: Virtual and Override
Method Overloading: It is also called as Compile time
polymorphism and early binding
ADO.Net:
ADO.NET is a set of classes (Framework), that can be used to interact with
data sources like Databases and xml files. This data can be consumed in
any .NET application.
ADO = Microsoft ActiveXData object
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;

namespace ADOCUSTOMERLIB
{
public class Employees
{
public void ConnectEmployees()
{
string strConnectionstring = "Data Source=DESKTOP-383K38T;Initial
Catalog=Office;Integrated Security=True;Trust Server Certificate=True";
SqlConnection objSqlConnection = new SqlConnection();
objSqlConnection.ConnectionString = strConnectionstring;

objSqlConnection.Open();
Console.WriteLine("you connect db");

string strCommand = "GetAllEmployees";


SqlCommand objsqlCommand = new SqlCommand(strCommand, objSqlConnection);
objsqlCommand.CommandType = System.Data.CommandType.StoredProcedure;

SqlDataReader dataReader = objsqlCommand.ExecuteReader();

if (dataReader.HasRows)
{
Console.WriteLine("EmployeID || lastName || FirstName || BirthDate || Photo ||
Notes ");
while (dataReader.Read())
{
Console.WriteLine("{0} || {1} || {2} || {3} || {4} || {5}
||", dataReader[0], dataReader[1], dataReader[2], dataReader[3], dataReader[4],
dataReader[5]);
}

}
}
}
}
With PARAMETERS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;

namespace WithParamLIB
{
public class EmployeesWithParam
{
public void GetEmployees(int EmployeesId)
{
string strConnectionstring = "Data Source=DESKTOP-383K38T;Initial
Catalog=Office;Integrated Security=True;Trust Server Certificate=True";
SqlConnection objSqlConnection = new SqlConnection();
objSqlConnection.ConnectionString = strConnectionstring;

objSqlConnection.Open();
Console.WriteLine("you connect db");

string strCommand = "GetEmployesById";


SqlCommand objsqlCommand = new SqlCommand(strCommand, objSqlConnection);
objsqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
objsqlCommand.Parameters.AddWithValue("@GetEmployeesById", EmployeesId);

SqlDataReader dataReader = objsqlCommand.ExecuteReader();

if (dataReader.HasRows)
{
Console.WriteLine("EmployeID || lastName || FirstName || BirthDate || Photo ||
Notes ");
while (dataReader.Read())
{
Console.WriteLine("{0} || {1} || {2} || {3} || {4} || {5}
||", dataReader[0], dataReader[1], dataReader[2], dataReader[3], dataReader[4], dataReader[5]);
}

}
}
}

You might also like