C/.NET PowerPoint PPT Presentation

presentation player overlay
About This Presentation
Transcript and Presenter's Notes

Title: C/.NET


1
C/.NET
  • Jacob Lewallen

2
C vs .NET
  • .NET is a platform.
  • Many languages compile to .NET
  • VB.NET
  • Python.NET
  • Managed C
  • C

3
.NET
  • Intermediate Language (IL) half-way
  • Interpreted locally using JIT (Just-In-Time)
    compilers.
  • Has a very nice standard library, comparable to
    Javas.
  • Theme More open to its hosted system than
    Java.

4
C Basics
  • Garbage Collected
  • Very Java-esque
  • Main is static method in some class
  • Designed for .NET, rather than adapted.
  • Simple operator overloading
  • Everything is an Object
  • Java-like inheritance

5
Safe vs Managed
  • Unmanaged native code - non-IL code.
  • Unsafe code code wrapped in Cs unsafe
    mechanism
  • Relaxed type checking
  • Pointers
  • Flagged as unsafe and requires more trust.
  • Unsafe code is still managed code.

6
Syntax
  • Think Java, if that fails think C
  • public class ExampleApp
  • public static void Main()
  • string str Hello, World
  • Console.WriteLine(str)

7
Namespaces
  • More like C namespaces, with some Java packages
    sprinkled in.
  • using System.Collections
  • Instead of using
  • System.Collections.Hashtable
  • Assemblies (DLLs) are named for the namespaces
    they contain, usually.

8
Declaring a Namespace
  • You can wrap your code in the namespace like so
  • Namespace UCR.Technical.Seminar
  • Nearly all code Ive ever seen has been wrapped
    in a Namespace.

9
Collections
  • System.Collections.Hashtable
  • System.Collections.ArrayList
  • Type-safe enumerations
  • foreach (string name in users)
  • .NET will do runtime type checking.

10
Memory
  • All allocated memory is garbage collected.
  • We use new to create object instances.
  • We can override a finalizer for our classes to
    handle cleanup.

11
Value Types
  • Categories Struct, Enumeration, Numeric Types
    (integers, floats, bools)
  • Assignments create copies of the assigned value.
  • Value types cannot contain null.
  • int is an alias for System.Int32, all value types
    have an alias.

12
Reference Types
  • Also referred to as objects.
  • Store references to actual data.
  • Passed by reference, by default.

13
Boxing
  • Boxing - conversion from a value type to type
    object. Its implicit
  • int x 23
  • object o 23 object r x
  • x is an integer on the heap, value is 23.
  • o is an object, referencing a new value on the
    heap, thats 23.
  • r is an object, referencing the value x.

14
Unboxing
  • Explicit conversion from a reference type, an
    object, to a value type.
  • object o 23
  • int x (int)o
  • Type checking is done in the conversion.
  • Can throw InvalidCastExceptions.

15
Properties
  • Replaces getter/setter paradigm.
  • Wraps private member variables around more
    defined accessors.
  • object.getName() you do object.Name.
  • object.setName(Jacob) becomes object.Name
    Jacob
  • Standard library uses upper case names for all
    properties.

16
Properties
  • Syntax for declaring a Property
  • String Name
  • get return (m_name)
  • set m_name value
  • Where m_name is our member variable.
  • Read-only Properties have no set.

17
Events/Delegates
  • Calling/invoking methods w/o knowing anything
    about the methods object.
  • Defining a Delegate
  • public delegate void ButtonDelegate(string name)
  • This delegate takes a string and returns nothing.

18
Defining a Delegate
  • Declare a variable for out delegate
  • private ButtonDelegate m_presses
  • We can create an instance of her
  • m_presses new ButtonDelegate(SayHello)
  • public bool SayHello(string name)
  • Now, we can invoke/trigger the delegate
  • m_presses(Hello, World)

19
Using Delegates
  • Delegates are used exclusively for event handling
    in .NET GUIs.
  • Many design patterns (publisher/subscribe)

20
Microsoft Whining
  • You can download the .NET SDK from Microsoft.
    Youll get
  • All the necessary command line utilities for
    developing with C.
  • A few graphical tools for inspecting IL.
  • Help via http//msdn.microsoft.com/
  • Visual Studio is NOT required.

21
Mono
  • Open Source .NET/C implementation
  • http//www.go-mono.com/

22
Assembly
  • Think shared-object - .dll or .so.

23
ADO.NET
24
System.XML
Write a Comment
User Comments (0)
About PowerShow.com