1 / 32

C #

C #. A Semitone Higher. History. We first begin with Java which was released in 1995 by Sun Microsystems Initially Java was 100% interpreted at runtime and was very slow Eventually Just-in-Time compilers were created and used

cicada
Download Presentation

C #

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C# A Semitone Higher

  2. History • We first begin with Java which was released in 1995 by Sun Microsystems • Initially Java was 100% interpreted at runtime and was very slow • Eventually Just-in-Time compilers were created and used • The increased performance of Java and portability helped it grow in popularity

  3. History • The theory that Java applications could be developed on Windows and then easily be deployed on Unix platforms was clearly a threat to Microsoft • So Microsoft created their own Java Virtual Machine which was fairly reliable • However, their JVM introduced incompatible extensions which ruined portability

  4. History • So Sun sued Microsoft for violating the licensing terms • This hindered Microsoft’s JVM making it obsolete quickly as Sun updated their JVM • Clearly Microsoft and Java did not mix well

  5. History • In 1999 Anders Hejlsberg of Microsoft and his team began working on a new language initially called COOL (C-like Object Oriented Language) • The name was eventually changed to C# by the time it was announced, along with Microsoft’s .NET, in 2000

  6. History • James Gosling claimed that C# was an “imitation” of Java • “[C# is] sort of Java with reliability, productivity and security deleted.” • Klaus Kreft and Angelika Langer (authors) • “Java and C# are almost identical programming languages. Boring repetition that lacks innovation.”

  7. History • However, over time Java and C# have taken different paths

  8. Overview • Part of the .NET Framework • Compiler creates intermediate code (CIL) • CLR creates machine code • Just-in-time compilation

  9. .exe or .dll • C# code can be compiled either to executable files or to library files (dynamically linked library) • cscprogram.cs compile to executable • csc /t:library lib.cs  compile to dll

  10. C like language • For the most part, if you have programmed in Java, C, C++ or any other C like language, you will be used to most C# syntax • C# uses {..} block statements • If else, while, do/while, for statements all the same • Even many keywords are the same (especially compared to Java)

  11. Object Oriented • At the heart it is object oriented • Supports inheritance and polymorphism • Classes are like objects with members • methods, constructors, etc.

  12. Basic Program • The Main method • static void Main() {…} • static void Main(string[] args) {….} • static int Main() {….} • static int Main(string[] args) {…} • “Other overloaded versions of Main are permitted, however, provided they have more than one parameter, or their only parameter is other than type string[].” - Microsoft

  13. Identifiers and Keywords • C# has 80 keywords • Some are context sensitive keywords • They can be used as identifiers • All keywords are usable as identifiers if the @ symbol is in front of them • @return, @null, @double • int @int = 5; Console.WriteLine(@int);

  14. Formatted Output • For output: • Console.WriteLine(…..); • Format using {…} within a string • {parameter #, spacing : special formatting} • Console.WriteLine(“{0,-10}.”, 100); • > 100. • ...WriteLine(“{1}, {0}”, firstName,lastName); • >Rahimi, Shahram

  15. Basic Programs

  16. Basic Programs

  17. Types • Value Types • sbyte, short, int, long, byte (unsigned), ushort, uint, ulong, char, float, double, decimal, bool • Enum, Struct, Nullable • Reference Types • Objects, string, class, interface, array, delegate

  18. Arrays • Arrays are treated the same as in Java • int[] n = new int[]{1,2,3,4}; SAME AS • int[] n = {1,2,3,4}; SAME AS • int[] n = new int[4]; n[0] = 1; …..

  19. Types • Nullable type • int?  allows the int values to also be null • Useful for databases • Delegates • A data structure that refers to one or more methods • Similar to function pointers in C and C++

  20. Delegates

  21. Delegates

  22. Switch • Switch statements are mostly the same EXECPT that they require an explicit branch statement like break or goto due to a static semantic rule • Also, switch statements in C# allow strings along with int and char

  23. Switch

  24. Unsafe Code • While C# has made strides to eliminate the need for pointers as data types with references and objects, it is still allowed • One must declare unsafe code to: • Declare and operate on pointers • Perform conversions between pointers • Take addresses of variables

  25. Unsafe Code • Variables • Methods • Classes

  26. Readability • Pro • Basic syntax is C like (recognizable) • Data must be explicitly typed and declared • Very common special words and statement structure (loops and selection) • Con • Not necessarily simple (delegates) • Overloaded Main • Keywords as identifiers • All statements end with }

  27. Writability • Pro • Many ways to do one thing (like array declaration) • Delegates can simplify method calling • Inheritance • Con • 80 keywords to remember (and required context)

  28. Reliability • Pro • Limits use of pointers, programmer becomes very aware of possible pointer issues. • Uses explicitly typed and declared variables • Con • Can write code in unsafe mode • Can be a complex language

  29. Cost • Memory references and automatic garbage collection make creating quality code simpler and faster • Uses Microsoft Visual Studio as compiler • Free open source versions are available, but premium versions can cost $2,000+ • Similar to well known languages but can be a complex language

  30. Who is using C# It’s Microsoft Who isn’t using it? • Web design • Gaming • Medical • Financial

  31. Mono Project • UNIX version of the Microsoft .NET development platform • Open sourced based on C# .NET framework • Enables Multi platform UNIX .NET applications • Implements various technologies developed by Microsoft that have now been submitted to the ECMA for standardization.

  32. Sources • “C# In Depth” – Jon Skeet • Wikipedia • http://en.wikipedia.org/wiki/C_Sharp_(programming_language) • “C sharp Language Specification” – Microsoft • “Concepts of Programming Languages” -Sebesta • “Essential C# 4.0” – Michaelis • http://www.mono-project.com/

More Related