Professional Documents
Culture Documents
A Brief Introduction To C#: David Buksbaum
A Brief Introduction To C#: David Buksbaum
David Buksbaum
Agenda
Goals Background Information C# - Up and Running Quick Comparison to Java Networking Namespaces References
Goals
Provide enough information to allow you to follow the code samples Highlight key differences with Java Tell you where you can get the compilers Tell you where to go for more details on C# Tell you where to go for more detailed comparisons with Java Not to debate which is better, more important, faster, slower, or looks better in emacs
Quick Glossary
BCL Base Class Library CLR Common Language Runtime GUI Graphic User Interface MSIL Microsoft Intermediate Language MS Microsoft SCM Service Control Manager SOA Service Oriented Architecture
.NET
.NET is:
Microsofts Platform for Windows Development CLR the Virtual Machine that runs MSIL aka MS Byte Code BCL aka .NET Framework A set of compilers that can generate MSIL C#, Visual Basic, C++, Java (the MS flavor)
C#
Language Created by Anders Hejlsberg (father of Delphi) The Derivation History can be viewed here: http://www.levenez.com/lang/history.html Principle Influencing Languages:
C++ Delphi Java
C# - Up and Running
A Simple C# Application Application Types Compiler & Run Time
A Sample C# Application
Application Types
Console Application
Has standard streams (out, in, err) GUI can be added manually
Windows Application
GUI based No standard streams (out, in, err) Main thread is shared by the GUI message pump & your code
Service
No standard streams (out, in, err) Main thread is commandeered by the SCM No GUI
Options Beyond MS
Mono
Open source development SDK for .NET Windows, Linux, Mac OS X, Solaris, Unix Sponsored by Novell
Food for thought: Suse + KDE + Mono = ???
Sharp Develop
Open source IDE that uses .NET SDK or Mono Written in C#
Exceptions
No throws keyword See
http://msdn.microsoft.com/chats/transcripts/vstudio/vstudio_ 032103.aspx
Type Aliasing
using newtypename = namespace.type;
Delegates
Type safe function pointers To create
public delegate bool CompareHandler(object left, object right);
To use
CompareHandler ch = new CompareHandler(myMethod); bool retval = ch(obj1, obj2);
Boxing / Unboxing
Conversion between value type and reference type packet p = new packet(); object o = (object)p; // boxed packet p2 = (packet)o; // unboxed Significant performance cost!
Assemblies
Similar to Java JAR files Physically they are EXE and/or DLL files
Methods not marked virtual are equivalent to Java final methods Methods can be marked with new to break the virtual chain
.Net 3.0
Its all about data
Tuples & Query constructs public void Linq1() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var lowNums = from n in numbers where n < 5 select n; Console.WriteLine("Numbers < 5:"); foreach (var x in lowNums) { Console.WriteLine(x); } } Result Numbers < 5: 4 1 3 2 0
Networking Namespaces
System.Messaging
Functionality for MSMQ
System.Net
Provides access to higher protocols (FTP, HTTP, DNS)
System.Net.Information
Network information classes providing statistics, interface information, and ping
System.Net.Sockets
Light weight wrappers around TCP and UDP sockets
System.Runtime.Remoting
Provides functionality for high level distributed programming (similar to RMI)
System.Web
Provides high level access to HTTP
References
Links
.NET SDK
http://www.microsoft.com/downloads/details.aspx?FamilyI D=fe6f2099-b7b4-4f47-a244c96d69c35dec&DisplayLang=en
MS Visual Studio
http://msdn.microsoft.com/vstudio/
Links cont.
MONO
http://www.mono-project.com/Main_Page
Sharp Develop
http://www.icsharpcode.net/OpenSource/SD/
Links cont.
C# Links
http://msdn1.microsoft.com/en-us/default.aspx http://gotdotnet.com/ http://www.c-sharpcorner.com/ http://msdn.microsoft.com/community/codezone/ http://en.wikipedia.org/wiki/C_Sharp_programming_langua ge
Online Tutorials
http://www.csharp-station.com/Tutorial.aspx http://www.c-sharpcorner.com/Tutorials.asp
Books
Programming C#, Fourth Edition by Jesse Liberty (http://search.barnesandnoble.com/booksearch/isbnInquiry.a sp?z=y&isbn=0596006993&itm=2) CLR Via C#: Applied Microsoft .Net Framework 2.0 Programming by Jeffrey Richter (http://search.barnesandnoble.com/booksearch/isbnInquiry.a
sp?z=y&isbn=0735621632&itm=3)