Unit - 1 & 3 (C# Programming BCA - 4)
Unit - 1 & 3 (C# Programming BCA - 4)
NET
B.C.A. (Semester – 4)
By :
Dr. BHAVESH K. LUKKA
M.Sc., Ph.D. (Comp. Science)
Assistant Professor,
Dr. V. R. Godhaniya College Of
Engineering & Technology
Porbandar
References :
C# is the most powerful programming language among all programming languages available in
the .NET framework because it contains all the features of C++, VB.NET, and JAVA, and also has
some additional features. The .NET Framework Redistributable package contains everything
needed to run a program under the .NET Framework. It includes the Common Language Runtime
(CLR), CTS, CLS etc…
Although C# constructs closely follow traditional high-level languages, C and C++ and being an
object-oriented programming languages. It has a strong resemblance with Java, it has
numerous strong programming features that make it endearing to a number of programmers
worldwide. Following is the list of a few important features of C# −
1. Simple: C# is a simple language in the sense that it provides a structured approach (to
break the problem into parts), a rich set of library functions, data types, etc.
2. Modern Programming Language: C# programming is based upon the current trend and it is
very powerful and simple for building scalable, interoperable, and robust applications.
4. Type-Safe: C# type safe code can only access the memory location that it has permission to
execute. Therefore, it improves the security of the program.
9. Rich Library: C# provides a lot of inbuilt functions that make development fast.
10. Fast Speed: The compilation and execution time of the C# language is fast.
1. Windows Applications
2. Web Applications
5. Console Applications
Visual Studio is one of the Microsoft IDE tools. Using this tool, we can develop, build,
compile, publish and run applications with the .NET framework. This tool provides some
features such as
1. Editor
2. Compiler
Operating System
Common Type System (CTS)—Common Type System (CTS) describes how types are declared,
used and managed. CTS facilitate cross-language integration, type safety, and high
performance code execution.
.NET Framework introduces a Common Type System, or CTS. The CTS specification defines
all the possible data types and programming constructs supported by the CLR and how they
may or may not interact with each other conforming to the Common Language Infrastructure
(CLI) specification. Because of this feature, .NET Framework supports the exchange of types
and object instances between libraries and applications written using any conforming .NET
language.
Common Language Specification (CLS)—. The CLS is a specification that defines the rules to
support language integration. This is done in such a way, that programs written in any
language (.NET compliant) can interoperate with one another. This also can take full
advantage of inheritance, polymorphism, exceptions, and other features.
Base Class Library—The Base Class Library consists of several thousand type definitions, where
each type exposes some functionality. It contains a huge library of reusable types, classes,
interfaces, structures and enumerated values, which are collectively called types, the CLR and the
Base Class Library allow developers to build the following kinds of applications:
Web Services : Components that can be accessed over the Internet very easily.
Web Forms : HTML based applications (Web Sites).
Windows Forms : Rich Windows GUI applications. Windows form applications can
take advantage of controls, mouse and keyboard events and can talk directly to the
underlying OS.
Windows Console Applications : Compilers, utilities and tools are typically
implemented as console applications.
Windows Services : It is possible to build service applications controllable via the
Windows Service Control Manager (SCM) using the .NET Framework.
Component Library : .NET Framework allows you to build stand-alone components
(types) that may be easily incorporated into any of the above mentioned application
types.
Common Language Runtime — CLR (Common Language Runtime) is considered as the heart of
the .NET framework. It serves as the execution engine. The .NET applications are compiled to
a common language known as Microsoft Intermediate Language or “IL”. The CLR, then,
handles the compiling the IL to machine language, at which point the a program is executed.
It performs memory management, exception handling, debugging, security checking, thread
execution, code execution, code safety, verification and compilation.
ADO .NET (DATA AND XML)— ADO.NET is the next generation of Microsoft ActiveX Data
Object (ADO) technology. ADO.NET is heavily dependent on XML for representation of
data. It also provides an improved support for the disconnected programming model.
ADO.NET’s DataSet object, is the core component of the disconnected architecture of
ADO.NET. The DataSet can also be populated with data from an XML source, whether it
is a file or an XML stream.
Visual Studio — This optional development tool contains a rich set of productivity and
debugging features. Visual Studio is one of the Microsoft IDE tools. Using this tool, we
can develop, build, compile, publish and run applications with the .NET framework. This
tool provides some features such as
1. Code Editor
2. Compiler
Code Editor
Solution Explorer
Server Explorer
The CIL code is housed in CLI assemblies. As mandated by the specification, assemblies are
stored in the Portable Executable (PE) format, common on the Windows platform for
all DLL and EXE files.
Metadata is Data about Data that contains complete name of an assembly contains its
simple text name, version number, culture.
In the .NET Framework, all the Microsoft .NET languages use a Common Language Runtime,
which solves the problem of installing separate runtimes for each of the programming
languages.
When the Web Forms page is implicitly compiled, it is actually compiled twice. On the first
pass, it is compiled into IL. On the second pass, the assembly in IL is compiled into machine
language. This process is called Just-In-Time JIT compilation because it does not occurs
until the assembly is on the target machine. The reason you do not compile it ahead of time
is so that the specific JITter for your OS and processor type can be used. As a result, the
assembly is compiled into the fastest possible machine language code, optimized and
enhanced for your specific configuration. It also enables you to compile once and then run
on any number of operating systems.
JIT Types
In Microsoft .NET there are three types of JIT (Just-In-Time) compilers which are explained as
under:
Pre-JIT COMPILER
Pre-JIT compiles complete source code into native code in a single compilation cycle. This
is done at the time of deployment of the application.
Econo-JIT COMPILER
Econo-JIT compiles only those methods that are called at runtime. However, these
compiled methods are removed when they are not required.
Normal-JIT COMPILER
Normal-JIT compiles only those methods that are called at runtime. These methods are
compiled the first time they are called, and then they are stored in cache.
When the same methods are called again, the compiled code from cache is used for
execution.
These methods are compiled the first time they are called, and then they are stored in
cache. When the same methods are called again, the compiled code from cache is used
for execution.
Managed code runs in the Common Language Runtime. Managed Code is what VB.NET and
C# compilers create. It compiles to Intermediate Language (IL), not to machine code that
could run directly on your computer. The CIL is kept in a file called an assembly, along with
metadata that describes the classes, methods, and attributes (such as security requirements)
of the code you've created.
Unmanaged code is what you use to make before Visual Studio .NET 2002 was released.
Visual Basic 6, Visual C++ 6 all produced unmanaged code. It compiled directly to machine
code that run on the machine when you compile it—and on other machines as long as they
had the same chip, or nearly the same. It didn't get services such as security or memory
management from an invisible runtime; it got them from the operating system. And
importantly, it got them from the operating system explicitly, by asking for them, usually by
calling an API provided in the Windows SDK.
DIFFERENT TYPES OF PROJECTS IN VISUAL STUDIO IDE:-
1. Console Application
C# can be used to create applications that take input and display output at the command
line console. These applications are ideal for learning C# development because the user
interface is so simple.
Console applications are also very useful for utility programs that require little or no user
interaction.
These applications rely on desktop computer power to process and display high-
performance content.
Some Windows Form Applications might be entirely self-contained and perform whole
processing on the user's computer. Games are often codded in this way. Other applications
might be a part of a larger system and use the desktop computer primarily for processing
user input.
3. Class Library
A key feature of the .NET Framework is the base class library. The .NET Framework class
library is made up of namespaces. Each namespace contains types that you can use in your
program: classes, structures, enumerations, delegates, and interfaces.
When you create a Visual Basic or Visual C# project in Visual Studio, the most common base
class DLLs (assemblies) are already referenced. However, if you have to use a type that is in
a DLL not already referenced, you will have to add a reference to the DLL.
The Windows Control Library project template is used to create custom controls to use on
Windows Forms.
You use ASP.NET Web Forms to create applications that primarily have a browser user
interface
Web Forms applications are platform-independent—that is, they are "reach" applications.
Users can interact with your application regardless of what type of browser they have and
even what type of computer they are using.
We can also develop mobile applications and many more with the help of .NET… …
Data Type Tree
Boxing and Unboxing
The concept of Boxing and Unboxing is related with Value Type and Reference Type. See the example
bellow to get the idea about it.
Windows Form
Windows Forms is a Graphical User Interface (GUI) class library which is bundled in .Net
Framework. Its main purpose is to provide an easier interface to develop the applications for
desktop, tablet, PCs. It is also termed as the WinForms. The applications which are
developed by using Windows Forms or WinForms are known as the Windows Forms
Applications that runs on the desktop computer. WinForms can be used only to develop the
Windows Forms Applications not web applications. WinForms applications can contain the
different type of controls like labels, list boxes, tooltip etc.
The events in the lifecycle of a Form from the time it is launched to the time it is closed
arelisted below:
Move This event occurs when the form is moved. Although by default, when a
form is instantiated and launched, the user does not move it, yet this
event is triggered before the Load event occurs.
Load This event occurs before a form is displayed for the first time.
VisibleChanged This event occurs when the Visible property value changes.
Activated This event occurs when the form is activated in code or by the user.
Deactivate This event occurs when the form loses focus and is not the active form.
AcceptButton Gets or sets the button on the form that is clicked when the user presses
the ENTER key.
CancelButton Gets or sets the button control that is clicked when the user presses the
ESC key.
MaximizeBox Gets or sets a value indicating whether the Maximize button is displayed
in the caption bar of the form.
MinimizeBox Gets or sets a value indicating whether the Minimize button is displayed in
the caption bar of the form.
ControlBox Gets or sets a value indicating whether a control box is displayed in the
caption bar of the form.
Menu Gets or sets the Main Menu that is displayed in the form.
Opacity Gets or sets the opacity level of the form.
ShowInTaskbar Gets or sets a value indicating whether the form is displayed in the
Windows taskbar.
StartPosition Gets or sets the starting position of the form at run time.
CenterParent, CenterScreen, Manual, WindowsDefaultBounds,
WindowsDefaultLocation
WindowState Gets or sets a value that indicates whether form is minimized, maximized,
or normal.
IsMDIContainer Gets or sets a value indicating whether the form is a container for
multiple-document interface (MDI) child forms.
Common Control Properties
Properties Description
BackColor Gets or sets the background color of the control.
BackgroudImage Gets or sets the background image displayed in the control.
Cursor Gets or sets the cursor that is displayed when the mouse pointer is
over the control.
Enabled Gets or sets a value indicating whether the control can respond to
userinteraction.
Font Gets or sets the font of the text displayed by the control.
ForeColor Gets or sets the foreground color of the control.
Height Gets or sets the height of the control.
Name Gets or sets the name of the control.
Size Gets or sets the height and width of the control.
TabIndex Gets or sets the tab order of the control within its container.
TabStop Gets or sets a value indicating whether the user can give the focus to
thiscontrol using the TAB key.
Text Gets or sets the text associated with this control.
Visible Gets or sets a value indicating whether the control and all its child
controls are displayed.
Width Gets or sets the width of the control.
Common Control Events
TextBox Control
(System.Windows.Forms.TextBox)
Properties of TextBox
Methods of TextBox
KeyPress Occurs when control got focus and user press or release any key
RichTextBox
(System.Windows.Forms.RichTextBox)
Properties
Properties
Maximum Default Value – 100. Gets or sets the upper limit of values of the
scrollable range.
Minimum Default Value – 0. Gets or sets the lower limit of values of the scrollable range.
Value Default Value - 0
Gets or sets a numeric value that represents the current position of the
scroll box on the scroll bar control.
SmallChange Default Value - 1
Gets or sets the value to be added to or subtracted from the Value
property when the scroll box is moved a small distance.
LargeChange Default Value - 10
Gets or sets a value to be added to or subtracted from the Value property
when the scroll box is moved a large distance.
Events
Scroll - Occurs when the scroll box has been moved by either a mouse or keyboard action.
ListBox
(System.Windows.Forms.ListBox)
Properties
Method
FindString() Finds the first item in the ListBox that starts with the specified
SetSelected() Selects or clears the selection for the specified item in a ListBox.
Events
SelectedIndexChanged
MenuStrip
(System.Windows.Forms.MenuStrip)
RadioButton Control
(System.Windows.Forms.RadioButton)
Radio Button generally used as group. Sometimes refers as option buttons. You can use
panel or group box control to generate group of radio buttons.
Properties
Gets or sets a value indicating whether the ellipsis character (...) appears at the
right edge of the control, denoting that the control text extends beyond the
specified length of the control.
Gets or sets a value indicating whether the Checked value and the appearance
of the control automatically change when the control is clicked.
Events
CheckedChanged Occurs when the value of the Checked property changes.
CheckBox Control
(System.Windows.Forms.CheckBox)
Properties
Gets or sets a value indicating whether the ellipsis character (...) appears at the
right edge of the control, denoting that the control text extends beyond the
specified length of the control.
Checked True, False
Gets or set a value indicating whether the CheckBox is in the checked state.
CheckState Unchecked, Checked, Indeterminate
Gets or sets the state of the
CheckBox.
ThreeState True, False
Gets or sets a value indicating whether the CheckBox will allow three check
states rather than two.
Event
Properties
Nodes Gets the collection of tree nodes that are assigned to the tree
Property: Count view control.
Indexer: this[int32]
Methods: Add()
Insert()
Remove()
RemoveAt(
)
Clear()
SelectedNode Gets or sets the tree node that is currently selected in the
Properties FirstNode treeview control.
FullPat
h Index
LastNode
ShowLines True, False
ShowPlusMinus True, False
PathSeparator ‘/’
Events
AfterSelect
AfterCollapse, BeforeCollapse
AfterExpand, BeforeExpand
PictureBox
(System.Windows.Forms.PictureBox)
Properties
Image Path/Location
SizeMode Normal, StretchImage, AutoSize, CenterImage, Zoom
ComboBox
(System.Windows.Forms.ComboBox)
Properties
Methods
Events
SelectedIndexChanged
Timer
(System.Windows.Forms.Timer)
Properties
Gets or sets the time, in milliseconds, before the Tick event is raised relative to the last
occurrence of the Tick event.
Events
Tick Occurs when the specified timer interval has elapsed and the timer is enabled.
Methods
Start() Starts the timer.
You can use Panel control when you have to show and hide a
group of controls.
Properties
Methods
Add(), Clear(), Contains(), Hide(), Show()
GroupBox
(System.Windows.Forms.GroupBox)
A GroupBox control is a container control that is used to place Windows Forms child controls
in a group.
Properties :
Methods :
Add(), Clear(),Remove(),
RemoveAt(), Contains()
Panel GroupBox
The Panel control can display the scroll bar. The GroupBox control cannot display the
Panels have auto scroll property. scroll bar.
A Panel control can’t be placed with A GroupBox control can be placed with atitle
a title (text). (text).
Panel’s border is determined by its A GroupBox always displays a border.
BorderStyle property.
It has the double click event. It does not have the click event.
It has also got MouseMove, MouseDown, The events that are missing include
MouseUp events.. MouseMove, MouseDown, MouseUp events..
Dialog Boxes
OpenFileDialog
(System.Windows.Forms.OpenFileDialog)
Filter Gets or sets a filter string that specifies the file types
and descriptions todisplay in the OpenFileDialog.
SaveFileDialog
(System.Windows.Forms.SaveFileDialog)
Page | 29
Programming With C#.NET BCA - 4th
ColorDialog
(System.Windows.Forms.ColorDialog)
Color Gets or sets the color selected by the user.
AllowFullOpen Gets or sets a value indicating whether the user can use the dialog
box todefine custom colors.
FontDialog
(System.Windows.Forms.FontDialog)
Font Gets or sets the selected font.
Color Gets or sets the selected font color.
ShowColor Gets or sets a value indicating whether the dialog box displays the
color choice.
Page | 30