1 / 24

C#/.NET

C#/.NET. Jacob Lewallen. C# vs .NET. .NET is a platform. Many languages compile to .NET: VB.NET Python.NET Managed C++ C#. .NET. Intermediate Language (IL) – “half-way” Interpreted locally using JIT (Just-In-Time) compilers. Has a very nice standard library, comparable to Java’s.

arion
Télécharger la présentation

C#/.NET

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#/.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 Java’s. • Theme: More “open” to it’s 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 C#’s 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 I’ve 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 object’s. • Store references to actual data. • Passed by reference, by default.

  13. Boxing • Boxing - conversion from a value type to type object. It’s 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, that’s 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 InvalidCastException’s.

  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 method’s 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 GUI’s. • Many design patterns (publisher/subscribe)

  20. Microsoft Whining • You can download the .NET SDK from Microsoft. You’ll 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

More Related