Successfully reported this slideshow.
Your SlideShare is downloading. ×

Week 2: Getting Your Hands Dirty – Part 2

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 14 Ad

Week 2: Getting Your Hands Dirty – Part 2

Download to read offline

In this presentation, the most important object oriented topics and features of C# is discussed. The session was presented in 42nd Session of CodeWeekend and it is the 3rd week of C# + CS50 Series of Training.

In this presentation, the most important object oriented topics and features of C# is discussed. The session was presented in 42nd Session of CodeWeekend and it is the 3rd week of C# + CS50 Series of Training.

Advertisement
Advertisement

More Related Content

Slideshows for you (20)

Similar to Week 2: Getting Your Hands Dirty – Part 2 (20)

Advertisement

More from Jamshid Hashimi (20)

Recently uploaded (20)

Advertisement

Week 2: Getting Your Hands Dirty – Part 2

  1. 1. Getting Dirty – Part 2 Jamshid Hashimi, CodeWeekend
  2. 2. Agenda • Structs • Interfaces • Introduction to Delegates and Events • Introduction to Exception Handling • Static Properties & Methods • Using Attributes • Enums • Overloading Operators • Introduction to Generic
  3. 3. Structs • Struct is a value type • Classes are reference types • Structs can’t have destructors, classes do. • The power of objects lies in their ability to mimic real-world behavior, through inheritance and polymorphism. • Supports interface inheritance • Structs are best used for storing data, but the lack of inheritance and references can be a serious limitation.
  4. 4. Interfaces • An interface looks like a class, but has no implementation. • It contains declarations of: • Events, methods, properties.. • Inherited by classes and structs • Interfaces can inherit other interfaces
  5. 5. Delegates and Events • Delegates are just function pointers, That is, they hold references to functions. • Delegation is when you request a service by making a method call to service provider. • The service provider then reroutes this service request to another method, which services the request. • The delegate class can examine the service request and dynamically determines at runtime where to route the request. • Example: A manager receives a service request, she often delegates it to a member of her department.
  6. 6. Delegates and Events • Events are variables of type delegates. • Events are user actions such as key press, clicks, mouse movements, etc., or some occurrence such as system generated notifcations. • Applications built with the .NET Framework are object-oriented, event-driven programs. • In Windows Applications, the user interacting with a GUI usually initiates the event. • A security class could broadcast an event message when an invalid login is detected. • You can subscribe to external events.
  7. 7. Introduction to Exception Handling • Exceptions are unforeseen errors happen in your programs. • There are times where you don’t know if an error will happen • I/O error • Run out of system memory • Database and more • You want to deal with them and this where Exception Handling comes in.
  8. 8. Static Properties & Methods • When you declare an object instance of a class, the object instantiates its own instances of the properties and methods of the class it implements. • However, sometimes you may want different object instances of a class to access the same, shared variables.
  9. 9. Attributes • Attributes are elements that allow you to add declarative information to your programs.
  10. 10. Enums • If you have a number of constants that are logically related to each other, then you can group together these constants in an enumeration. • Enums are strongly typed constants which makes the code more readable and less prone to errors. • You can specify another integral numeric type by using a colon. • Enum allows us to create a new data type.
  11. 11. Overloading Operators • You can redefine or overload most of the built-in operators available in C#. • Operator overloading provides a much natural abstraction for the types. • Overloaded operators are functions with special names the keyword operator followed by the symbol for the operator being defined.
  12. 12. Generics • Generics allow you to delay the specification of the data type of programming elements in a class or a method, until it is actually used in the program • Generics allow you to write a class or method that can work with any data type. • Features • It helps you to maximize code reuse, type safety, and performance. • You can create your own generic interfaces, classes, methods, events, and delegates. • And more..
  13. 13. Source Codes: http://www.facebook.com/groups/CodeWeekend
  14. 14. Thank You!

Editor's Notes

  • Useful link: http://www.codeproject.com/Articles/4773/Events-and-Delegates-Simplified

×