0% found this document useful (0 votes)
17 views

Unit 2 C#

The document discusses objects, classes, namespaces, assemblies and other core .NET concepts. An object is an instance of a class that encapsulates state and behavior. A class is a template used to create objects. Namespaces are used to organize classes and control scope. Assemblies are compiled code files that contain one or more namespaces.

Uploaded by

chauhanjeel57
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)
17 views

Unit 2 C#

The document discusses objects, classes, namespaces, assemblies and other core .NET concepts. An object is an instance of a class that encapsulates state and behavior. A class is a template used to create objects. Namespaces are used to organize classes and control scope. Assemblies are compiled code files that contain one or more namespaces.

Uploaded by

chauhanjeel57
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/ 15

 Object and Class

 C# Object
 In other words, object is an entity that has state and behavior. Here, state means
data and behavior means functionality.
 Object is a runtime entity, it is created at runtime.
 Object is an instance of a class. All the members of the class can be accessed
through object.
 Let's see an example to create object using new keyword.
 Student s1 = new Student();//creating an object of Student
 In this example, Student is the type and s1 is the reference variable that refers to
the instance of Student class. The new keyword allocates memory at runtime.

 C# Class
 class is a group of similar objects. It is a template from which objects are created.
It can have fields, methods, constructors etc.
 Let's see an example of C# class that has two fields only.

Ex: public class Student


{
int id;
String name;
}

public class Student


{
int id;
String name;
public static void Main(string[] args)
{
Student s1 = new Student();
s1.id = 101;
s1.name = "Sonoo Jaiswal";
Console.WriteLine(s1.id);
Console.WriteLine(s1.name);
}
}
 Namespace

 Namespaces are used to organize the classes.


 It helps to control the scope of methods and classes in larger .
Net programming projects.
 A namespace is a section of code that is identified with a specific
name.
Defining
namespace Namespace-Name
{
//Body of namespace
}
For example:
namespace MyNamespace
{
class MyClass
{
public void MyMethod()
{
System.Console.WriteLine("Creating my namespace");
}
}
}
Accessing Members
The members of a namespace can be accessed using the dot(.) operator. The syntax for
accessing the member of namespace is,
 Namespace-Name.Member-Name

 global namespace is the root namespace. The global::System
will always refer to the namespace "System" of . Net Framework
using System;
using First;
using Second;

namespace First
{
public class Hello
{
public void sayHello() { Console.WriteLine("Hello Namespace"); }
}
}
namespace Second
{
public class Welcome
{
public void sayWelcome() { Console.WriteLine("Welcome Namespace"); }
}
}
public class Test Namespace
{
public static void Main()
{
Hello h1 = new Hello();
Welcome w1 = new Welcome();
h1.sayHello();
w1.sayWelcome();
}
}

Output: Hello Namespace


Welcome Namespace
 Assembly

 It is a collection of code files that are compiled into an executable or


a Dynamic Link Library (DLL).
 An Assembly is a basic building block of .Net Framework applications
 A .NET program may contain one or more assemblies.
 An assembly is a file that is automatically generated by the compiler upon
successful compilation of every .NET application.
 Assembly files are the result of the C# compiler reading in human
readable C# source files
 .NET assemblies are files which have either a .exe or a .dll extension.
 The first type is a file that is executable, like we just saw above.
 Dll files are a little bit different. A dll file means it is what is known as a
dynamic link library.
 Dll files are not executed like an exe file, but they can be loaded by
other programs and run the code contained in them.
 The .NET assemblies are part of the Global Assembly Cache on a
Windows computer.
 The assemblies stored in the GAC can be used by any .NET applications
running on the computer.
 GAC:
 GAC stands for Global Assembly Cache. - It is an area of
memory reserved to store the assemblies of all . NET
applications that are running on a certain machine.

 TYPES

 Private Assemblies:

 An Assembly that is solely used by one application is referred to as a Private


Assembly.

 It is typically found in the directory for the application or a subdirectory of the


directory for the programme.
 Private Assemblies are not intended to be shared with other applications. They
are used to store application-specific code and resources.

 Shared Assemblies:

 An assembly that is used by several programmes is referred to as a shared


assembly.

 It is typically found in the Global Assembly Cache (GAC) or a common directory.

 Multiple applications are supposed to share a shared assembly.

 They are used to store resources and code that are shared by various
applications.

 Shared Assemblies are created using the strong name tool (sn.exe).

 Satellite Assemblies:

 An assembly used to store regional resources is referred to as a Satellite


Assembly.

 It is typically found in a subdirectory of the directory for the application or a


subdirectory of the directory for the Shared Assembly.

 Localized resources like strings, pictures, and audio files are kept in satellite
assemblies.

 Satellite Assemblies are created using the resgen.exe tool.

 The resgen.exe tool is used to create a resource file (.resx) from a text file.

 Dynamic Link Libraries (DLLs):

 A Dynamic Link Library (DLL) is a type of assembly that contains code that can
be used by multiple applications.
 DLLs are created with the intention of being used by numerous
applications. DLLs, however, differ from shared assemblies in that they do not
have a distinctive name.

 DLLs are kept in the directory of the application or a subdirectory of the directory
of the application.

 They can be used by multiple applications by simply copying the DLL to the
application's directory.

 DLLs are created using the same tools that are used to create shared assemblies.

 However, DLLs do not require a strong name. They can be signed with a digital
signature, but this is optional.

 Web Server
 Web server is a computer where the web content is stored.
 web server is used to host the web sites but there exists other web servers also such as
gaming, storage, FTP, email etc.
 Web site is collection of web pages whileweb server is a software that respond to the request
for web resources.

 Web Server Working


 Web server respond to the client request in either of the following two ways:
 Sending the file to the client associated with the requested URL.
 Generating response by invoking a script and communicating with database
 When client sends request for a web page, the web server search for the requested page if
requested page is found then it will send it to client with an HTTP response.
 If the requested web page is not found, web server will the send an HTTP
response:Error 404 Not found.
 If client has requested for some other resources then the web server will contact to the
application server and data store to construct the HTTP response.

 Architecture
 Web Server Architecture follows the following two approaches:
1. Concurrent Approach
 Concurrent approach allows the web server to handle multiple client requests at the same
time. It can be achieved by following methods:
 Multi-processing
 In this a single process (parent process) initiates several single-threaded child processes
and distribute incoming requests to these child processes. Each of the child processes are
responsible for handling single request.
 It is the responsibility of parent process to monitor the load and decide if processes
should be killed or forked.
 Multi-threaded
 it creates multiple single-threaded process.
 Hybrid
 It is combination of above two approaches.

 Web Based Application


 A web application is application software that is accessed
using a web browser.
 Web applications are delivered on the World Wide Web to
users with an active network connection.
 A web-based application is any program that is accessed
over a network connection using HTTP, rather than existing
within a device's memory.
 Web applications do not need to be downloaded since they
are accessed through a network.
 Users can access a web application through a web browser,
such as Google Chrome, Mozilla Firefox or Safari.
 it's also called browser based applications. a web-based software offers an interactive user
interface.
 The client-side script deals with user interface functionality
like buttons and drop-down boxes. When the end user clicks
on the web app link, the web browser loads the client-side
script and renders the graphic elements and text for user
interaction.
 The server-side script deals with data processing. The web
application server processes the client requests and sends
back a response. The requests are usually for more data or
to edit or save new data.
 Window Based Application
 A program that is written to run under the Microsoft Windows operating
system, also called a "Windows app.
 " All 32-bit Windows applications run in the 32-bit and 64-bit versions of
Windows.
 All 64-bit applications require 64-bit Windows, which is the standard on
new Windows computers and tablets.
 Windows application is easy to build. Windows-based applications data
validation is carried out through code
 Windows-based applications data validation is carried out through code
 Windows application have better authorization and administrators have more
control, making them more secure.
 Windows applications are faster in speed
 Ex. VLC Media player running on Windows OS will not run on MacOS and Linux.
 Windows applications typically have a native user interface
 HTML Controls

 HTML server controls are HTML elements that contain attributes to


accessible at server side.
 We can convert an HTML element to server control by adding
a runat="server" and an id attribute to the component.
 Ex. <input id="UserName" type="text" size="50"runat="server" />
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"> <title></title> </head>
<body>
<form id="form1" runat="server">
<div>
<input id="Text1" type="text" runat="server"/>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>
</div>
</form>
</body>
</html>

 ASP .NET Control

 ASP.NET provides web forms controls that are used to create HTML components.
 ASP.NET CheckBox

 It is used to get multiple inputs from the user. It allows user to select choices
from the set of choices.
 It takes user input in yes or no format. It is useful when we want multiple choices
from the user.

 To create CheckBox we can drag it from the toolbox in visual studio.

 This is a server side control and ASP.NET provides own tag to create it. The
example is given below.

< asp:CheckBox ID="CheckBox2" runat="server" Text="J2EE"/>

 Server renders it as the HTML control and produces the following code to the
browser.

< input id="CheckBox2" type="checkbox" name="CheckBox2" /><label for="CheckBox2">J2EE</label>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Select Courses</h2>
<asp:CheckBox ID="CheckBox1" runat="server" Text="J2SE" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="J2EE" />
<asp:CheckBox ID="CheckBox3" runat="server" Text="Spring" />
</div>
<p>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /
>
</p>
</form>
<p>
Courses Selected: <asp:Label runat="server" ID="ShowCourses"></asp:Label>
</p>
</body>
</html>
 ASP.NET ListBox

 The ListBox Control provides us a user interface that will display the List of the
items.
 The list box is like a set of radio buttons except that the list box is scrollable
and can contain more items than a set of Radio Buttons.
 The number of entries added to the list box can also be at the run time.
 The list box is a web server control.
 It allows the selection of single and multiple items in the list

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> An example of ASP.Net ListBox</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Choose a color:</h2>
<asp: ListBox ID ='ListBox1’ runat = 'server'>
<asp: ListItem> Dark Grey </asp: ListItem>
<asp: ListItem> Red </asp: ListItem>
<asp: ListItem> Green </asp: ListItem>
<asp: ListItem> Blue </asp:ListItem>
<asp: ListItem> Yellow </asp: ListItem>
<asp: ListItem> Black </asp: ListItem>
</asp: ListBox>
</div>
</form>
</body>
</html>
 Rich Control
1.FileUpload control
 FileUpload control is used to browse and upload files. After the file is
uploaded, you can store the file on any drive or database. FileUpload
control is the combination of a browse button and a text box for entering
the filename.

The FileUpload control supports the following important properties.


 FileBytes: It returns the contents of uploaded file as a byte array
 FileContent: You can get the uploaded file contents as a stream.
 FileName: Provides the name of uploaded file.
 HasFile: It is a Boolean property that checks whether particular file is
available or not.
 PostedFile: Gets the uploaded file wrapped in the HttpPostedFile object.

2.Calendar control
 Calendar control provides you lots of property and events. By using these
properties and events you can perform the following task with calendar
control.

 Select date.
 Selecting a day, a week or a month.
 Customize the calendar's appearance.

3.AdRotator control
 AdRotator control is used to display different advertisements randomly in
a page.
 The list of advertisements is stored in either an XML file or in a database
table. Lots of websites uses AdRotator control to display the
advertisements on the web page.

4.MultiView control
 MultiView control can be used when you want to create a tabbed page.
 In many situations, a web form may be very long, and then you can
divide a long form into multiple sub forms.
 MultiView control is made up of multiple view controls. You can put
multiple ASP.NET controls inside view controls.
 Common Properties ASP .Net

 Bin Directory
 ASP.NET projects used to compile all the source files into an assembly and put them into
a folder called "Bin"
 it used to compile all files into a DLL and copy them to the special folder called "Bin".
 The bin folder holds binary files, which are the actual executable code for your
application or library.

 Virtual Directory
 A virtual directory represents a web application and it points to a physical folder in
your computer.
 A web application is accessed using a virtual directory name instead of a physical
folder name
 A virtual directory is a user-defined directory name that is configured in Internet Information
Services (IIS) and linked to a physical directory on the local server's storage
 How to create a virtual directory by using IIS Manager

 In IIS Manager, expand the local computer and the Web site to which you want to add a virtual
directory.

 Right-click the site or folder in which you want to create the virtual directory, click New, and
then click Virtual Directory.

 In the Add Virtual Directory dialog box, at a minimum enter information in the Alias and
Physical path and then click OK.

You might also like