Introduction to C - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Introduction to C

Description:

C# is a part of a wide range of technologies produced by Microsoft ... 3rd Party Compilers: Borland C# Builder, Mono (open source) THREE GUIDING PRINCIPLES ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 19
Provided by: KP683
Category:

less

Transcript and Presenter's Notes

Title: Introduction to C


1
Introduction to C
  • By Kevin Pond

2
C its more than just a note
  • C is a new language in the C, C family
  • Its modern, simple, object-oriented, and type
    safe
  • C is a part of a wide range of technologies
    produced by Microsoft known as .NET

3
Isnt C only Microsoft?
  • C was designed by Microsoft
  • Microsoft has worked to make C an open standard
  • The CLI foundation is an open standard
  • 3rd Party Compilers Borland C Builder, Mono
    (open source)

4
THREE GUIDING PRINCIPLES
  • Simple Preservation
  • Incremental Improvement
  • Thoughtful Innovation

5
Simple Preservation
  • If C or C addresses a problem well, nothing was
    changed
  • Expressions, statements, and overall syntax are
    derived from C and C
  • Programmers from C and C should feel
    comfortable from the beginning

6
(A few of the) Incremental Improvements
  • Variables must be initialized
  • if and while expressions must evaluate to Boolean
    values to prevent accidental mistakes like
    instead of at compilation
  • No silent fall-through in switch statements
    (omitting break statements irritates the
    compiler)

7
Thoughtful Innovation
  • Automatic memory management
  • Unified Type System (everything is an object!)
  • Properties, Methods, and Events are fundamental
    (more on this later)
  • Enhanced documentation and attributes (more on
    this later)

8
Show me the CODE
  • namespace CSharpPractice
  • class HelloWord
  • static void Main()
  • System.Console.WriteLine(Hello World)

9
One-Stop Programming
  • Similar to Java style
  • Unlike C there is no need for header files
  • The idea hear is that classes should be
    encapsulated modules that could easy be added
    to other programs

10
Namespaces
  • Method of grouping elements (such as classes and
    other namespaces) to avoid naming collisions
  • Namespaces are also in C
  • Syntax for accessing elements belonging to a
    namespace is the . operator
  • C syntax is the operator

11
Why Namespaces??
  • Namespaces are meant for HUGE programs and
    frameworks
  • In a huge program with different modules designed
    by different companies there may be classes with
    the same name
  • If each company uses their company name as their
    namespace, naming collisions are reduced
    substantially

12
Namespace Example 1
  • namespace MyCompany
  • class Grid
  • class OtherClass

Now when the user of Grid wants to reference it
the coder would have to first qualify (explain to
the compiler) which class we are talking about by
prefixing the class name with the namespace name
i.e. MyCompany.Grid
13
Main method
  • Every program must have one class with the method
    Main
  • Works just like main in C
  • Must be static (more on this later)

14
Writing Text to Console
  • To write text to the console in our simple
    program we called the method System.Console.WriteL
    ine
  • This probably seems a little tedious
  • To save on typing we have the using directive

15
using
using System namespace MyCompany class
SimpleProgram static void Main()
Console.WriteLine(hi)
Now since we added the using System directive,
the compiler will use things in the System
namespace without needing to specifically be told
the namespace i.e. we can type Console.WriteLin
e(hi) Instead of System.Console.WriteLine(hi
)
16
When you use dont confuse
using A using B namespace A class C
public static method void foo()
System.Console.WriteLine(sup)
namespace B class C public
static method void foo()
System.Console.WriteLine(homie)
\\class with Main defined below
This code wont compile. The using directive
basically puts everything inside a namespace into
the global namespace. Therefore if items in
different namespaces share the same name, using
both of them will introduce ambiguity and the
compiler will scream.
17
C (.NET) Applications
  • All .NET applications written in .NET compatible
    languages have access to the .NET platform and
    interoperate seamlessly
  • This is possible through the MSIL
  • MSIL cannot execute directly therefore exe made
    in .NET actually call the JITter
  • The JITter basically compiles the MSIL when a
    function is called

18
JIT aint it
  • Install-time code generation an applications
    MSIL can be completely compiled at install-time
  • EconoJit systems with little RAM can discard
    compiled assemblies when low on memory
Write a Comment
User Comments (0)
About PowerShow.com