Page 15 - DCAP505_MODERN_PROGRAMMING_TOOLS_AND_TECHNIQUES_II
P. 15

Unit 1: Introduction to C#




          Borrowing from languages like SQL, C# implements built-in support for data types like decimal   Notes
          and string, and lets you implement new primitive types that are as efficient as the existing ones.
          You’ll also be happy to see that C# takes a more modern approach to debugging. The traditional
          way to write a debug-able program in C++ was to sprinkle it with #ifdefs and indicate that large
          sections of code would only be executed during the debugging process. You would end up with
          two implementations-a debug build and a retail build, with some of the calls in the retail build
          going to functions that do nothing. C# offers the conditional keyword to control program flow
          based on defined tokens.
          Finally, C# is designed to be easy to parse, so vendors can create tools that allow source browsing
          and two-way code generation.

          Object Oriented

          C++ is object oriented. That’s why C# ditches multiple inheritance in favor of native support for
          the COM+ virtual object system. Encapsulation, polymorphism, and inheritance are preserved
          without all the pain.
          C# ditches the entire concept of global functions, variables, and constants. Instead, you can create
          static class members, making C# code easier to read and less prone to naming conflicts.
          And speaking of naming conflicts, have you ever forgotten that you created a class member
          and redefined it later on in your code? By default, C# methods are non-virtual, requiring an
          explicit virtual modifier. It’s far harder to accidentally override a method, it’s easier to provide
          correct versioning, and the vtable doesn’t grow as quickly. Class members in C# can be defined
          as private, protected, public, or internal. You retain full control over their encapsulation.

          Methods and operators can be overloaded in C#, using a syntax that’s a lot easier than the one
          used by C++. However, you can’t overload global operator functions-the overloading is strictly
          local in scope. The overloading of method F below is an example of what this looks like:
                 interface ITest
                 {
                     void F();             // F()
                     void F(int x);        // F(int)
                     void F(ref int x);    // F(ref int)
                     void F(out int x);    // F(out int)
                     void F(int x, int y); // F(int, int)
                     int F(string s);      // F(string)
                     int F(int x);         // F(int)

                 }
          The COM+ component model is supported through the implementation of delegates-the object-
          oriented equivalent of function pointers in C++.




              Task  Interfaces support multiple inheritance. Explain with proper program.

          Classes can privately implement internal interfaces through explicit member implementations,
          without the consumer ever knowing about it.





                                           LOVELY PROFESSIONAL UNIVERSITY                                     9
   10   11   12   13   14   15   16   17   18   19   20