Zig Ziglars Secrets of Closing The Sale PDF
Zig Ziglars Secrets of Closing The Sale PDF
Zig Ziglars Secrets of Closing The Sale PDF
Lab Manual
Dot NET
2014-2015
Programming with .NET
Introduction
Hello World
Comments
Data types
Enumerations
Arrays
Variables and constants
Expressions
Statements
Classes
Inheritance
Interfaces
Exception handling
Events
Delegates
C#
Hello World
using System;
{
public class HelloWorld
{
public static void Main()
{
Console.WriteLine("Hello World in C#");
}
}
}
C# classes are stored in .cs files. After you have saved the preceding
program in a file, let's say Hello World, you can compile the program
into a .NET executable. You will need to include the .NET Framework
SDK's bin folder in your PATH variable. If you have installed Visual
Studio .NET, you have a shortcut under Visual Studio .NET Tools called
Visual Studio .NET 2003 Command Prompt. This shortcut initializes all
the environment variables and provides access to the command-line
compilers as well.
csc HelloWorld.cs
Now enter HelloWorld.exe to run the application, and you should see
"Hello World in C#" echoed on the screen.
Comments
Table 3.1 describes how the C# types are mapped into the corresponding
.NET Framework types. In a true sense, the C# keywords are really a
compact representation for the .NET type.
Enumerations
Arrays
using System;
{
public class UseArrays
{
public static void Main()
{
String[] days_of_week = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
foreach (string day in days_of_week)
{
Console.WriteLine(day);
}
}
}
}
PROGRAM 4
Simple value types can be assigned using the variable = value construct,
whereas reference types are required to use the new keyword for
creating a new instance.
using System;
{
public class UseVariables
{
public static void Main()
{
const string HELLO_WORLD = "Hello World";
string message = HELLO_WORLD+ " in C#";
MyClass mc = new MyClass(message);
mc.Print();
}
}
public class MyClass
{
private String message;
public MyClass(String message)
{
this.message = message;
}
public void Print()
{
Console.WriteLine(message);
}
}
}
PROGRAM 5
Expressions
Statements
using System;
{
public class UseStatements
{
public static void Main()
{
string[] message = {"Hello", "World",
"in", "C#"};
foreach (string msg in message)
{
Console.Write(msg+" ");
}
Console.WriteLine("");
int a = 10;
int b = 20;
if (a < b)
{
Console.WriteLine("a<b");
}
else
{
Console.WriteLine("a>=b");
}
}
}
}
PROGRAM 6
Structures
Console.WriteLine(hs.FirstName+"."+hs.LastName);
Console.WriteLine(jd.FirstName+"."+jd.LastName);
}
}
public struct Person
{
public string FirstName, LastName;
public Person(string FirstName, string
LastName)
{
this.FirstName = FirstName;
this.LastName = LastName;
}
}
}
PROGRAM 7
Classes
Classes, on the other hand, are reference types and hence are allocated
on the heap. Classes provide object-oriented constructs such as
encapsulation, polymorphism, and inheritance. For instance, the
following program would print John.Doe twice, illustrating that objects
are reference types, allocated on the heap.
using System;
{
public class UseClasses
{
public static void Main()
{
Person hs = new Person("Hitesh","Seth");
Person jd = hs;
jd.FirstName = "John";
jd.LastName = "Doe";
Console.WriteLine(hs.GetFullName());
Console.WriteLine(jd.GetFullName());
}
}
public class Person
{
private string sFirstName, sLastName;
public Person(string FirstName, string
LastName)
{
this.sFirstName = FirstName;
this.sLastName = LastName;
}
public string FirstName
{
get
{
return sFirstName;
}
set
{
sFirstName = value;
}
}
public string LastName
{
get
{
return sLastName;
}
set
{
sLastName = value;
}
}
public String GetFullName()
{
return this.FirstName + "."+
this.LastName;
}
}
}
PROGRAM 8
Inheritance
using System;
namespace hks
{
public class UseInheritance
{
public static void Main()
{
FullPerson hs = new
FullPerson("Hitesh","K","Seth");
Console.WriteLine(hs.GetFullName());
Object oHs = hs;
if (oHs is Person)
{
Console.WriteLine("I am still a
Person");
}
}
}
public class Person
{
public string FirstName, LastName;
public Person(string FirstName, string
LastName)
{
this.FirstName = FirstName;
this.LastName = LastName;
}
public virtual string GetFullName() {
return this.FirstName + "." +
this.LastName;
}
}
public class FullPerson : Person
{
public string MiddleInitial;
public FullPerson(string FirstName, string
MiddleInitial,
string LastName) :
base(FirstName,LastName)
{
this.MiddleInitial = MiddleInitial;
}
public override string GetFullName() {
return this.FirstName + "." +
this.MiddleInitial + "." + this.LastName;
}
}
}
PROGRAM 10
Interfaces
Exception Handling
Delegates
Events
Visual Basic .NET is the next revision of the popular Visual Basic
programming language, which has roots in the BASIC programming
language itself. Known for its rapid application development capability,
Visual Basic .NET provides developers with the benefits of rapid
development with a full-blown object-oriented (OO) programming
language. Visual Basic .NET builds on the basic OO features present in
Visual Basic and makes the object- orientedness of the language on par
with that of Visual C# and even C++.
With its human-readable code syntax, Visual Basic .NET follows a task-
oriented model. Focus on increased developer productivity still remains
the core mantra for Visual Basic. Key features of the Visual Basic .NET
programming language include the following:
Hello World
The program listing that follows will look both familiar and different to
existing Visual Basic programmers. Familiar is the overall style,
subroutines, and modules. What is different in the program is really the
additional keyword—Namespace—and the use of -the .NET
Framework class library. An important thing to keep in mind is that
Visual Basic .NET is not a case-sensitive programming language.
Imports System
Module HelloWorld
Public Sub Main()
Console.WriteLine("Hello World in VB")
End Sub
End Module
End Namespace
Visual Basic .NET programs are stored with the .vb extension. To
compile a Visual Basic .NET program, use the Visual Basic. NET J#
command-line compiler, vbc.exe.
vbc HelloWorld.vb
Comments
Visual Basic comments are plain old ' style line comments or are
identified by Rem.
Imports System
Module Comments
Rem Implement the Main Method
Public Sub Main()
' Print Out Hello World
Console.WriteLine("Hello World in VB")
End Sub
End Module
End Namespace
Data Types
Table 3.2 describes how the Visual Basic .NET types are mapped to
their corresponding .NET Framework types.
Enumerations
Arrays
Imports System
Namespace hks
Module UseArrays
Public Sub Main()
Dim days_of_week() as String = { _
"Sunday", _
"Monday", _
"Tuesday", _
"Wednesday", _
"Thursday", _
"Friday", _
"Saturday" _
}
Dim I as Integer
For I = 0 to days_of_week.Length-1
Console.WriteLine(days_of_week(I))
Next I
End Sub
End Module
End Namespace
Imports System
Namespace hks
Module UseVariables
Public Sub Main()
Const HELLO_WORLD as String = "Hello
World"
Dim msg as String = HELLO_WORLD & " in VB"
Dim mc as New MClass(msg)
Call mc.Print
End Sub
End Module
Class MClass
private message as String
Public Sub New(ByVal message as String)
Me.message = message
End Sub
Public Sub Print()
Console.WriteLine(message)
End Sub
End Class
End Namespace
Expressions
Statements
Classes in Visual Basic are defined using the Class keyword. Like C#,
VB classes can have members, constructors and destructors, properties,
methods (which are classified into subroutines and functions, depending
on whether they return a value), and events (Listing 3.9).
Exception Handling
Delegates