Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to the.NET Framework and C# NETbuilder - March 2009 Louis Botterill.

Similar presentations


Presentation on theme: "Introduction to the.NET Framework and C# NETbuilder - March 2009 Louis Botterill."— Presentation transcript:

1 Introduction to the.NET Framework and C# NETbuilder - March 2009 Louis Botterill

2 2 Agenda ● The.NET Framework and C# - an introduction – Origins and time-line – Versions and platform variants –.NET high level features – C# overview – C# examples and language features – Tools and GUI builder (quick demo) – Future – Resources and further reading

3 3 (Not covered in this presentation) ● Other languages, VB etc ● Server side programming ASP.NET ● WCF, WPF ● Silverlight, XAML and XBAP ● LINQ, LINQ to SQL, LINQ to XML etc ● Functional Programming ● ClickOnce etc ● * Can be covered in further presentations...

4 4 Origins ● From Microsoft, described as a “Software Framework” ● Microsoft started development on the.NET Framework in the late 1990s originally under the name of Next Generation Windows Services (NGWS). By late 2000 the first beta versions of.NET 1.0 were released ● The first release of the.NET Framework was on 13 February 2002

5 5 Versions Version Version Number Release Date Visual Studio Windows Version 1.0 1.0.3705.0 2002-02-13 VS.NET 1.1 1.1.4322.573 2003-04-24 VS.NET 2003 Server 2003 2.0 2.0.50727.42 2005-11-07 VS 2005 3.0 3.0.4506.30 2006-11-06 Vista, Server 2008 3.5 3.5.21022.8 2007-11-19 VS 2008 Windows 7

6 6.NET Framework / CLR.NETCLR1 1.112 32 3.52 44? TBA

7 7 Main variants ●.NET CLR – Desktop applications ●.NET CF – Mobile Applications ● ASP.NET – Server (web) applications

8 8 Overview features ● Virtual machine based ● Multi-platform (various Microsoft platforms) ● Multiple language support ● VM Garbage collection ● Byte-code is always compiled before execution, either Just In Time (JIT) or in advance of execution using the ngen.exe utility.

9 9 Language Support (Official) ● C# ● VB (Visual Basic) ● XAML ● JScript ● Powershell

10 10 Language support (Unofficial) ● IronPython ● IronRuby ● Boo ● IronLisp ● M ● Oxygene ● Nemerle ● Phalanger ● F# And others...

11 11 Some Basic terminology ● ASP – Active Server Pages ● CIL – Common Intermediate Language (formerly MSIL) ● CLI – Common Language Infrastructure ● CLR – common language runtime ● LINQ – Language Integrated Query ● WCF – Windows Communication Foundation ● WF – Windows workflow Foundation ● WPF – Windows Presentation Foundation ● XAML - Extensible Application Markup Language ● XBAP – XAML Browser APlication

12 12 Framework Stack

13 13 Some Key concepts ● Assemblies – are packages of code ● Managed code - is computer program code that executes under the management of a virtual machine, unlike unmanaged code, which is executed directly by the computer's CPU. ● Debug and release builds

14 14 Assemblies In the Microsoft.NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security. ● In the Microsoft Windows implementation of.NET, an assembly is a PE (portable executable) file for Windows GUI on Intel x86. There are two types: – process assemblies (EXE) – library assemblies (DLL) ● A process assembly represents a process which will use classes defined in library assemblies.

15 15 The Garbage Collector ● The.NET Garbage Collector (GC) is a non- deterministic, compacting, mark-and-sweep garbage collector. ● The GC runs only when a certain amount of memory has been used or there is enough pressure for memory on the system.

16 16 Language - C# ● C# (pronounced C Sharp) is a multi-paradigm programming language that encompasses functional, imperative, generic, object-oriented (class-based), and component-oriented programming disciplines. ● It was developed by Microsoft as part of the.NET initiative and later approved as a standard by ECMA (ECMA-334) and ISO (ISO/IEC 23270). C# is one of the programming languages supported by the.NET Framework's Common Language Runtime. ● Designed to be “Very Easy To Learn!”

17 17 Key Language Features ● Object orientated & Component orientated ● Imperative, Generic ● Bounds checking ● Run time type information ● Pass by value and Pass by reference ● Functions as first class objects ● Pre-processor support

18 18 Key Language Features (2) ● Strings are immutable ● Single inheritance for classes ● Multiple inheritance for interfaces ● Namespaces – like Java Packages (but much more flexible) ● C# Requires “definite assignment”

19 19 Ubiquitous Hello World! class Program { static void Main(string[] args) { System.Console.WriteLine(“Hello World!”); } ● Main - entry point, has two overloads Main() and Main(string[]) ● System namespace includes many common objects ● Arrays indexed using []

20 20 Hello World! v2 using System; namespace ConsoleApp { class Program { static void Main(string[] args) { Console.WriteLine(“Hello ” + args[0]); Console.ReadKey(); } ● using – bring a namespace into scope ● namespace – define a named scope for a block

21 21 The System namespace ● System – contains.NET types, Garbarge collector, Environment, Console ● System.Collections & System.Collections.Generic - collection classes ● System.Linq – Language Integrated Query ● System.Text – Encoders and decoders,.Regex, StringBuilder etc ● System.IO – File and Directory access, Readers and Writers ● System.Net – HTTP, FTP, sockets etc ● System.Threading – Thread related stuff

22 22 Numeric types Type SizeSigned byte8no ushort 16no uint32no ulong 64no sbyte8yes short16yes int32yes long64yes float 32yes double 64yes decimal 128yes

23 23 Type aliases ● Primitive types have keyword aliases, e.g. – string alias for System.String – int alias for System.Int32 – And so on...

24 24 Foreach using System; class Foreach { static void Main(string[] args) { foreach (string arg in args) { Console.WriteLine(arg); }

25 25 Properties class MyClass { private int x; public int X { get { return x; } set { if (x < 100) { x = value; } else { throw new ArgumentOutOfRange("x"); } public int Y { get; set; }; }

26 26 Indexers (indexed properties) public class MyList { private string[] items; public string this[int index] { set { return items[index]; } set { items[index] = value; }

27 27 Checked Integer arithmetic using System; class Overflow { static void Main() { try { int x = int.MaxValue + 1; // wraps to int.MinValue int y = checked(int.MaxValue + 1); // throws } catch (OverflowException caught) { Console.WriteLine(caught); }

28 28 Value types //enumeration types enum Suit { Hearts, Clubs, Diamonds, Spades } // structure types struct Rectangle { int x1, y1, x2, y2; } ● struct – no inheritance! ● struct members are private by default ● struct can have constructors ● struct can have static methods and fields ● readonly and const keywords Primitive types, enums, structs

29 29 Nullable types Provides support for nullable value types ● Example – Nullable ● The syntax T? is shorthand for System.Nullable ●.GetValueOrDefault(); returns value or default value for type ● Use the.HasValue and.Value read-only properties to test for null and retrieve the value ● The Value property returns a value if one is assigned, otherwise a System.InvalidOperationException is thrown ● Use the ?? operator to assign a default value that will be applied when a nullable type whose current value is null is assigned to a non-nullable type, for example int? x = null; int y = x ?? -1;

30 30 Enumerations (Enums) ● Value objects ● Strongly typed ● Can specific underlying types and values enum DayOfWeek : int { Monday = 1, Tuesday = 2, Wednesday = 4, Thursday = 8, Friday = 16, Saturday = 32. Sunday = 64 Weekend = Saturday | Sunday }

31 31 Reference types ● Class class Foo: Bar, IFoo {...} ● Interface interface IFoo: IBar {...} ● Arrays string[] strings = new string[10]; ● Delegates delegate void SomeDelegate(); ● Can all be Null!

32 32 Case statements ● No default fall-through ● Fall through Only on empty cases ● Can switch on non-numeric types i.e. string ● Use of Goto (yes really!) can be used to mimic case fall-through if necessary

33 33 Some (more unusual) Keywords ● sealed – like Java final, a class cannot be sub- classed ● partial – a class is defined across multiple files/blocks. ● static – can have static classes

34 34 Inheritance – virtual, override and new ● In a superclass, if a method is not polymorphic, then in its subclasses use the keyword new to provide a new definition that hides the original. ● In a superclass, if a method is polymorphic, use the keyword virtual. In its subclasses, use the keyword override to provide a new polymorphic overridden version. ● * Virtual methods must be explicitly overridden *

35 35 Example constructor syntax public class MyClass { public MyClass() {.... } public MyClass(int x) : this() {... } public MyClass(int x, int y) : this(x) {.... }

36 36 Example inheritance syntax public class MyClass : MyBaseClass, IMyInterface, IMyOtherInterface { public MyClass(int someValue) : base(someValue) {... }

37 37 Destructors public class MyClass : MyOtherClass { ~MyClass() { Do some cleanup...; } ● Destructor as per constructor but with ~ prefix, i.e. name same as class with no return ● Converted into protected Finalize override ● User never calls Finalize

38 38 Delegates namespace System { public delegate void EventHandler(object sender, EventArgs sent);... } namespace System.Windows.Forms { public class Button {... public event EventHandler Click; } using System.Windows.Forms; class MyForm : Form {... private void initializeComponent() {... okButton = new Button("OK"); okButton.Click += new EventHandler(this.okClick); // create + attach } private void okClick(object sender, EventArgs sent) {... }... private Button okButton; }

39 39 Actions and Functions ● Declaire a routine with no return Action myFunc = (int v1, string s) => { // Do some stuff... }; ● Declaire a function with a return var createForm = new Func (() => { MyLovelyForm myForm = new MyLovelyForm(); return myForm; });

40 40 Attributes ● Can be attached to types and members ● Consumed at run-time using reflection ● Based on a class that inherits from Attribute public abstract class ServiceResponseBase { [XmlElement(ElementName = "result", Namespace = "http://www.netbuilder.com/webtrader/common")] public abstract ServiceResponseElement Result { get; set; } [XmlElement(ElementName = "tss", Namespace = "http://www.netbuilder.com/webtrader/marketdata/tss")] public abstract TssElement TssElement { get; set; } }

41 41 Preprocessor directives ● #define, #undef ● #if, #elif ● #else, #endif ● #region some region name ● … code... ● #endregion

42 42 Tools and plug-ins ● Visual Studio (Pro) 2008 ● Visual Studio Express Edition 2008 SP1 ● Resharper (JetBrains) - http://www.jetbrains.com/resharper/ http://www.jetbrains.com/resharper/ – Powerful, but not that cheap. Trials available, we don't currently have any licenses. ● DevExpress – http://www.devexpress.com/ http://www.devexpress.com/ – tools and component libraries, Refactor and CodeRush etc ● Whole list of plug-ins on Wikipedia – http://en.wikipedia.org/wiki/List_of_Microsoft_Visual_Studio_Add-ins

43 43 Tools and plug-ins (2) ● TestDriven.net – Nunit integration ● VisualSVN – Tortoise SVN integration

44 44 Demo: Time to make a quick GUI ● Show the tools in action ● GUI builder ● Editing properties and events ● Adding event handlers ● Running and debugging

45 45 The future,.NET 4.0 ● Enhanced parallel computing - multi-core and distributed support ● IronPython and IronRuby support ● F# support ● Microsoft announced the.NET Framework 4.0 on September 29, 2008. While full details about its feature set have yet to be released, some general information regarding the company's plans have been made public. Some focus of this release are: ● * Improve support for parallel computing, which target multi-core or distributed systems. To this end, they plan to include technologies like PLINQ (Parallel LINQ), a parallel implementation of the LINQ engine, and Task Parallel Library, which exposes parallel constructs via method calls. ● * Full support for IronPython, IronRuby, and F#. ● * Support for a subset of the.NET Framework and ASP.NET with the "Server Core" variant of Windows Server 2008 R2

46 46.NET 4.0 ● Expected in 2010 (with Visual studio 2010) – Enhanced COM interoperability – Improved support for dynamic languages

47 47 Recommended Books ● Pro C# 2008 and the.NET 3.5 Platform, Fourth Edition - Andrew Troelsen – http://www.amazon.co.uk/Pro-2008-NET-Platform- Fourth/dp/1590598849/ref=sr_1_1?ie=UTF8&s=books&qid=1238583256&sr=1-1 http://www.amazon.co.uk/Pro-2008-NET-Platform- Fourth/dp/1590598849/ref=sr_1_1?ie=UTF8&s=books&qid=1238583256&sr=1-1 ● Programming C#: Building.NET Applications with C# - Jesse Liberty – http://www.amazon.co.uk/Programming-C-Building-NET- Applications/dp/0596006993/ref=sr_1_1?ie=UTF8&s=books&qid=1238583167&sr=8 -1 http://www.amazon.co.uk/Programming-C-Building-NET- Applications/dp/0596006993/ref=sr_1_1?ie=UTF8&s=books&qid=1238583167&sr=8 ● Professional C# 2008 (Wrox Professional Guides) – http://www.amazon.co.uk/Professional-C-2008-Wrox- Guides/dp/0470191376/ref=sr_1_3?ie=UTF8&s=books&qid=1238583256&sr=1-3 http://www.amazon.co.uk/Professional-C-2008-Wrox- Guides/dp/0470191376/ref=sr_1_3?ie=UTF8&s=books&qid=1238583256&sr=1-3 ● C# in Depth: What you need to master C# 2 and 3 - Jon Skeet – http://www.amazon.co.uk/C-Depth-What-need- master/dp/1933988363/ref=sr_1_4?ie=UTF8&s=books&qid=1238583535&sr=1-4 http://www.amazon.co.uk/C-Depth-What-need- master/dp/1933988363/ref=sr_1_4?ie=UTF8&s=books&qid=1238583535&sr=1-4

48 48 Resources and further reading ● http://msdn.microsoft.com/net http://msdn.microsoft.com/net ● Programmers overview - http://www.jaggersoft.com/pubs/AProgrammersOverviewOfCSharp.htm http://www.jaggersoft.com/pubs/AProgrammersOverviewOfCSharp.htm ● Comparison of C# to Java PDF - https://fhict.fontys.nl/Deeltijd/1JarigeStudies/CSA/Lesmateriaal/Week%201/Achtergrond/J ava%20and%20CSharp.pdf https://fhict.fontys.nl/Deeltijd/1JarigeStudies/CSA/Lesmateriaal/Week%201/Achtergrond/J ava%20and%20CSharp.pdf ● C# for C++ programmers - http://andymcm.com/csharpfaq.htm#5.3http://andymcm.com/csharpfaq.htm#5.3


Download ppt "Introduction to the.NET Framework and C# NETbuilder - March 2009 Louis Botterill."

Similar presentations


Ads by Google