Sunday, February 7, 2010

.Net Framework Application Development Foundation(1)

Week One Notes:
Date: 7 /Feb/ 2009

About .Net Framework software: 3.5 SP1 , Visual Studio 2008 SP1 , an optimized tool for VS 2008-> VS Resharper ;
Free download student edition VS 2008 Pro Edition :
https://www.dreamspark.com/Products/Product.aspx?ProductId=1

Reference Books:
1. Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition ( Apress)
2. MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework Application
Development Foundation, Second edition ( Microsoft Press)

Notes:
1. About .NET:
.NET is their foundation for future application developments. ‘.NET’ is a set of technologies that are aimed at enabling development over the internet as well as aimed at enabling devices to be connected together via a common platform (.NET). This includes Mobile devices, personal computers and other electronic devices.
DLL Hell -- no more in .Net( versioning issues) via version forwarding
Security -- more secure in .Net ( by using managed code)

2. About VC++ and J++ , VB
VC++ -- there are too many compatibility issue( driver issue)
VJ++ -- rarely used ( not popular)
VB -- too basic

3. About .Net Versions
.Net 1.0 no more use ( using CLR 1.0)
.Net 1.1 still works and widely used in legacy applications ( shipped with Windows
Server 2003 and Visual Studio 2003 , using CLR 1.0 )
.Net 2.0 popular and shipped with visual studio 2005 and Windows Server 2003 R2 , SQL
Server 2005 ; full 64bit support; using CLR 2.0
.Net 3.0 better integrated in Vista and server 2008 ; still using CLR 2.0 ; new components:
WCF , WPF , WFF , WCardspace( bad , rarely used)
.Net 3.5 came withVisual Studio 2008 . Shipped with Server 2008 R2 and Windows 7;
still using CLR 2.0 ; Linq included .
.Net 4.0 coming with Visual Studio 2010 ( still in Beta)

So, .Net 2.0 includes WinForms , Web Service and ASP.Net
.Net 3.0 includes .net 2.0 and WFF , WPF , WCF and CardSpace
.Net3.5 includes .net 3.0 and LINQ , AJAX and REST( rarely used , some web service)

4. Common Type System(C#)
Actually , some types are never used in production environment:
uint , ulong , ushort , float
Always using : byte , int , long , bool and double

5. Constant and read only variable
Const in C# : the value must be assigned in source code.
E.G. const int a = DateTime.Today.Year ; ( Error) the right side is a variable actually

Use keyword readonly if value can only be assigned at runtime ; can be set only once. After that, it behaves as a constant

6. Types
value types ( value type , enumeration and structure type ) -- object types( class and interface , array)

Each of the numerical types map to a corresponding structure in the System namespace. Structures are “value types” allocated on the stack.
String and object are “reference types,” meaning the variable is allocated on the managed heap (garbage-collected).
Value types can be allocated into memory very quickly and have a very
fixed and predictable lifetime.

7. Indexer ( extension method , properties)
public MyType this [int index]
{
set{} ; get{} ;
}

8. Practice:
a. decimal money = 12.45m ;
cw( money.toString("c")) or cw( "{0:c}" , money); -- 'C' means format currency

b. int.MinValue , int.MaxValue , ....
c. char input = (char) Console.Read() ; -- default int type returned
d. Utilities method : char.isDigit() , isLetter() , isLower() , isUpper() ;
e. type convert or cast
string str = 12 ; int num ; if( int.TryParse(str , out num)) ...
d. Checked keyword -- only check overflow exception
e. Nullable a = null or int? a = null ; a.HasValue , a.Value.ToString()
a ?? -1 if a is null , return -1 when a is int type or return a.Value
equals a.HasValue ? a.Value.ToString() : "N/A"

f. var type is good utility.
g. string , str.Split( new []{','} ) ; array.toList() and then we can use foreach with iterator
h. Linq to object is good . ( toList , select, lambda expression)

9.Debugging
Stopwatch class ; sw.Start() , Stop() , sw.Elapsed ; return execution duration ;

10 . DateTime and TimeSpan are of value types and structures defined by system.


=============================================================
Some Code
==============================================================
class Program
{
static void Main(string[] args)
{
///
/// Excercise one
/// About DateTime and TimeSpan structures ( value types)
/// ITIC Training Course -- Week One
/// Trainee : Tonny Yan
/// Instructor: Bing Xie
/// Date: 10/02/2010
///

DateTime birth = DateTime.Now;
TimeSpan interval = new TimeSpan();
TimeSpan interval2 = new TimeSpan(2, 14, 28); // using values explicitly

Console.WriteLine(interval.Equals(TimeSpan.Zero));// true
Console.WriteLine(TimeSpan.MinValue);
Console.WriteLine(TimeSpan.MaxValue);
Console.WriteLine(interval2.ToString());

// duration of a trip
// the order is year , month , day , hour , min and second ;
DateTime departure = new DateTime(2010, 6, 12, 18, 32, 0);
DateTime arrival = new DateTime(2010, 6, 13, 22, 47, 0);
TimeSpan travelTime = arrival - departure;
Console.WriteLine("{0} - {1} = {2}", arrival, departure, travelTime);

// excercise for Property of a class
Student aSt = new Student("tonny", "Yan");
Console.WriteLine(aSt.ToString());

}
}

// define a class with auto-implemented properties
public class Student
{
public string Fullname { get; private set; }// readonly
public string Firstname { private get; set; }// write only
public string Lastname { private get; set; }

public Student(string firstname, string lastname)
{
this.Firstname = firstname;
this.Lastname = lastname;
this.Fullname = firstname + " " + lastname;
}

public override string ToString()
{
return Fullname;
}

}

No comments:

Post a Comment