Dotnet Basic Slides
Dotnet Basic Slides
Shibu lijack
Shibu lijack
What is .NET?
.NET Framework
Back Office
Heterogeneous application and server infrastructure
Customer Service
Sales
So what is .NET?
.NET is a platform that provides a standardized
set of services.
Its just like Windows, except distributed over the Internet. It exports a common interface so that its programs can be run on any system that supports .NET.
.NET Framework
Programming model for .NET Platform for running .NET managed code in
a virtual machine Provides a very good environment to develop networked applications and Web Services Provides programming API and unified language-independent development framework.
Windows Forms
J#
Windows Forms
ASP .NET
Web Forms Web Services Mobile Internet Toolkit
C++
ASP .NET
Web Forms Web Services Mobile Internet Toolkit
Windows Forms
C++
C#
VB
Perl
J#
Windows Forms
Perl
J#
Video:-
LECTURE 02
Managed Code
Automatic Memory Management
Managed Code
Code that targets the CLR is referred to as
managed code All managed code has the features of the CLR
Object-oriented Type-safe Cross-language integration Cross language exception handling Multiple version support
Pointerless environment
It is low-level (machine) language, like Assembler, but is Object-oriented Implements various types (int, float, string, ) And operations on those types
CLS is a set of specifications that all languages and libraries need to follow
Intermediate Language
.NET languages are compiled to an
Intermediate Language (IL) IL is also known as MSIL or CIL CLR compiles IL in just-in-time (JIT) manner each function is compiled just before execution The JIT code stays in memory for subsequent calls Recompilations of assemblies are also possible
.NET Languages
Languages provided by Microsoft
C++, C#, J#, VB.NET, JScript Perl, Python, Pascal, APL, COBOL, Eiffel, Haskell, ML, Oberon, Scheme, Smalltalk
QUESTIONS????
LECTURE 03
OVERVIEW
C# Language
Console Applications
C# Language
Mixture between C++, Java and Delphi Component-oriented
Properties, Methods, Events Attributes, XML documentation All in one place, no header files, IDL, etc. Can be embedded in ASP+ pages Primitive types arent magic Unified type system == Deep simplicity Improved extensibility and reusability
C# Language Example
using System;
class HelloWorld { public static void main() { Console.WriteLine(Hello, world!); } }
Execution
Native Code JIT Compiler
Console Applications
private void button1_Click(object sender, EventArgs e) { MessageBox.Show("The first Windows app in the book!"); }
Output
SUMMARY
How the Visual Studio 2008 development
environment works
QUESTIONS????
LECTURE 04
OVERVIEW
Basic C# Console Application Structure
Naming Convention
Flow Control
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine("The first app in Beginning C# Programming!"); Console.ReadKey(); } } }
<type> <name>;
Video of output:-
Expressions
By combining operators with variables and
literal values (together referred to as operands
when used with operators), you can create expressions, which are the basic building blocks of computation.
Flow Control
Two methods of controlling program flow: Branching, where you execute code conditionally,
depending on the outcome of an evaluation. Looping, or repeatedly executing the same statements.
Output.
Video:-
Example for Enums:Namespace { enum orientation : byte { north = 1, south = 2, east = 3, west = 4 } class Program { static void Main(string[] args) { orientation myDirection = orientation. north; Console.WriteLine("myDirection = {0}", myDirection); Console.ReadKey(); } } }
Output
Video:-
Example for array:string[] friendNames = {"Robert Barwell", "MikeParry","Jeremy Beacock"}; int i; Console.WriteLine("Here are {0} of myfriends:",friendNames.Length); for (i = 0; i < friendNames.Length; i++) { Console.WriteLine(friendNames[i]); } Console.ReadKey();
Output
Summary
How basic C# syntax works? What Visual Studio does when you create
a console application project?
How to understand and use variables? How to understand and use expressions? Techniques for structuring your code
Exercises
Write a console application that obtains four int values from the
user and displays the product. Hint: you may recall that the Convert.ToDouble() command was used to covert the input from the console to a double; the equivalent command to convert from a string to an int is Convert.ToInt32().
QUESTIONS???
LECTURE 05
OVERVIEW
String Manipulation
Functions
Overloading and Delegate Functions
String Manipulation
string myString = "This is a test."; char[] separator = {' '}; string[] myWords; myWords=myString.Split(separator); foreach (string word in myWords) { Console.WriteLine("{0}", word); } Console.ReadKey();
Output
Video:-
Functions
Functions in C# are a means of providing blocks
of code that can be executed at any point in an
application.
Example..
class Program { static int MaxValue(int[] intArray) { int maxVal = intArray[0]; for (int i = 1; i < intArray.Length; i++) { if (intArray[i] > maxVal) maxVal = intArray[i]; } return maxVal; } static void Main(string[] args) { int[] myArray = {1, 8, 3, 6, 2, 5, 9, 3, 0, 2}; int maxVal = MaxValue(myArray); Console.WriteLine("The maximum value in myArray is {0}", maxVal); Console.ReadKey(); } }
Output
Video:-
Summary
Passing parameter arrays to functions
QUESTIONS???
Exercises
Write an application that uses two commandline arguments to place values into a string and
an integer variable, respectively. Then display these values.
LECTURE 06
OVERVIEW
Debugging and Error Handling
Debugging
Console.WriteLine("MyFunc() Function about to
be called.");
MyFunc ("Do something."); Console.WriteLine("MyFunc() Function execution completed.");
Exceptions
The C# language includes syntax for Structured
Exception Handling Try { ... } Catch (<exceptionType> e) { ... } finally { ... }
Objects
An object is a building block of an OOP application. This building
block encapsulates part of the application, which may be a process, a chunk of data, or some more abstract entity.
Objects in C# are created from types, just like the variables. We picture classes and objects using Universal Modeling Language
(UML) syntax. UML is a language designed for modeling applications, from the objects that build them up, to the operations they perform, and to the use cases that are expected.
UML representation
UML representation of printer class, called Printer and of an instance of this Printer class called myPrinter.
The member name. The type of the member. A colon is used to separate the member names
and types.
Methods
Method is the term used to refer
to functions exposed by objects. These may be called in the same way as any other function and may use return values and parameters in the same way.
Video:-
QUESTIONS???
LECTURE 07
OVERVIEW
OOP Techniques
OOP Techniques
Interfaces
Inheritance
Interfaces
An interface is a collection of
public methods and properties that are grouped together to encapsulate specific
functionality.
IDisposable
implement method
interface
the
must
Dispose()
Inheritance
Inheritance is one of the most important
features of OOP. Any class may inherit
from another, which means that it will have all the members that the class it inherits from has. In OOP terminology, the class being inherited (also known as derived) from is the parent class (also known as the base class).
OUTPUT..
Video:-
SUMMARY
What object-oriented programming is?
QUESTIONS???
EXERCISES
Write some code for a function that will accept
either of the two cup objects in the preceding example as a parameter. The function should call the AddMilk(), Drink(), and Wash() methods for any cup object it is passed.
LECTURE 08
OVERVIEW
Class definitions in C# Access Modifiers Interfaces The System.Object class Constructors and Destructors A comparison between interfaces and abstract classes
Class Definitions in C#
C# uses the class keyword to define classes.
The basic structure required is: class MyClass
{ // Class members.
Access Modifiers
Modifier none or internal public abstract or internal abstract public abstract sealed or internal sealed public sealed Meaning Class accessible only from within the current project Class accessible from anywhere Class accessible only from within the current project, cannot be instantiated, only derived from Class accessible from anywhere, cannot be instantiated, only derived from Class accessible only from within the current project, cannot be derived from, only instantiated Class accessible from anywhere, cannot be derived from, only instantiated
Video:-
Interfaces
Interfaces are declared in a similar way to
classes, but using the interface keyword rather than class. For example: interface IMyInterface { // Interface members. }
System. Object
Since all classes inherit from System. Object, all
classes will have access to the protected and
public members of this class.
System. Object contains the methods shown in the following table:Method Object() Return Type N/A Virtual No Static No Description Constructor for the System.Object type. Automatically called by constructors of derived types. Compares the object for which this method is called with another object and returns true if they are equal. The default implementation checks to see if the object parameter refers to the same object (because objects are reference types). This method can be overridden if you wish to compare objects in a different way, for example if they hold equivalent data. Returns a string corresponding to the object instance. By default, this is the qualified name of the class type (see earlier example), but this can be overridden to provide an implementation appropriate to the class type. Returns the type of the object in the form of a System.Type object. Used as a hash function for objects where this is required. A hash function is one that returns a value identifying the object state in some compressed form.
Equals(object)
bool
Yes
No
ToString()
string
Yes
No
GetType() GetHashCode()
System.Type int
No Yes
No No
Video:-
Constructors
A simple constructor can be added to a class
using the following syntax: class MyClass { public MyClass() { // Constructor code. } }
Video:-
Destructors
The destructors used in .NET is called Finalize().
class MyClass { ~MyClass() { // Destructor body. } }
Interfaces versus Abstract Classes Similarities: First, the similarities: both abstract classes and
interfaces may contain members that can be inherited by a derived class. Neither interfaces nor abstract classes may be directly instantiated, but you can declare variables of
these types.
Summary
How to define classes and interfaces in C#
LECTURE 09
OVERVIEW
We will here learn about field, property, and
method class members
Interface Implementation
Defining Fields
Fields are defined using standard variable
declaration format (with optional initialization),
along with the modifiers discussed previously. For example: class MyClass { public int MyInt; }
Defining Methods
Methods use standard function format, along
with accessibility and optional static modifiers.
For example:
class MyClass { public string GetString() { return "Here is a string."; } }
Defining Properties
Properties are defined using get and set
keywords.
public int MyIntProp {
Interface Implementation
Interface members are defined like class members except
for a few important differences: No access modifiers (public, private, protected, or internal) are allowed all interface members are implicitly public. Interface members can't contain code bodies. Interfaces can't define field members. Interface members can't be defined using the keywords static, virtual, abstract, or sealed. Type definition members are forbidden.
Summary
Learned how to define fields, methods, and
properties.
LECTURE 10
OVERVIEW
Collections
Comparisons
Generics
Collections
Collections enable you to maintain groups of
objects.
IEnumerable
Provides the capability to loop through items in
a collection. The IEnumerable interface requires only one method: GetEnumerator. The job of GetEnumerator is to return an object of a class that implements IEnumerator.
Current
IComparable
To sort the Array List, the objects in the array
must implement IComparable.
Comparisons
Here we come across two values: Type comparisons
Value comparisons
Type Conversion
Syntax:if (myObj.GetType() == typeof(MyComplexClass)) { // myObj is an instance of the class MyComplexClass. }
Value Comparison
Syntax:if (person1.Age > person2.Age) { ... } if (person1 > person2) { ... }
Generics
A generic class is one that is built around
whatever type, or types.
class MyGenericClass<T> { ... } Where T can be any identifier.
Followed by
A generic class can have any number of types
in its definition, separated by commas, for example: class MyGenericClass<T1, T2, T3> { ... }