GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

C Sharp

mangat.paul Englisch 5,0Durchschnittliche Bewertung 5,0 von 5 (1 Bewertung) 27 Karten

C Sharp

Karten in diesem Stapel (27)

  1. 1main features of a static classContains only static members.Cannot be instantiated.Is sealed.Cannot contain Instance Constructors.
  2. 2publicThe class member, that is defined as public can be accessed by other class member that is initialized outside the class. A public member can be accessed from anywhere even outside the namespace.
  3. 3privateThe private access specifiers restrict the member variable or function to be called outside from the parent class. A private function or variable cannot be called outside from the same class. It hides its member variable and method from other class and methods. However, you can store or retrieve value from private access modifiers using get set property.
  4. 4protectedThe protected access specifier hides its member variables and functions from other classes and objects. This type of variable or function can only be accessed in child class
  5. 5internalThe internal access specifier hides its member variables and methods from other classes and objects, that is resides in other namespace. The variable or classes that are declared with internal can be access by any member within application. It is the default access specifiers for a class in C# programming
  6. 6protected internalThe protected internal access specifier allows its members to be accessed in derived class, containing class or classes within same application. However, this access specifier rarely used in C# programming but it becomes important while implementing inheritance
  7. 7method hidinguse the "new" key word in the derived class
    to undo this use base.method() or typecast
    ((parentclass(derivedclass)).method()
    also can use:
    parentClass pc = new childClass();
  8. 8polymorphismpolymorphism allows you to invoke derived class methods through a base class reference at runtime:
    use "virtual" in base class and
    "override" in derived class
    parent[] pc = new parent[3];
    pc[0] = new parent();
    pc[1] = new derivedclass1();
    pc[2]= new derivedclass2();
    foreach...
  9. 9method parameters4 types
    1.value
    2.reference
    3.out
    4.parameter arrays
  10. 10methods passing a parameter by value vs. referencevalue just makes a copy of variable
    reference points to the same memory location:
    int i - 0;
    meth(ref i);
    public static void meth( ref int J)
    j=56;
    i and j equal
  11. 11out parameters used if multiple values need to be returned from a methodint total, int product;
    calc(2,5, out total, out product);
    public static void calc(int a, int b, out sum, out product)
    { sum = a=b;
    product = a*b;
    }
    notice no need for return ( return only for 1 value)
  12. 12parameter arraysparamsmeth(myArray);
    paramsmeth(1,2,3...10);
    public static void paramsmeth(params int[]);
    can only pass 1 params array,
    can pass other variables but params array must be last parameter
  13. 13private fields naming conventionuse an underscore before the variable name
    private int _test;
  14. 14"value" keywordpublic int id;
    get{}
    set{ if (value <0) error
    else this._id = value }
    your variable is passed into value
  15. 15propertieswe use get and set accessors to implement properties
    the advantage of using properties over traditional get() and set() methods is that you can make the fields public
  16. 16using properties for encapsulationprivate int _i;
    public int i;
    get{}
    set{}
  17. 17public string city {get; set;}shortcut method if no validation needed
    (private fields are created for you in background)
  18. 18object initializer syntaxcustomer cust1 = customer
    {
    Id =10,
    Name = Costco
    };
  19. 19struct vs. class-struct value type in stack
    -class reference type in heap
    -when you copy a struct a new copy of struct is created
    coping a class reference point to same heap location
    -no destructors in structs
    structs are sealed
    structs can inherit from interfaces
  20. 20InterfacesNaming: use capitol I (interface Icustomer)
    no implementations or fields allowed
    interface members are public so no access modifiers ... void print()...no public
    classes and structs can inherit multilpe interfaces..must provide all implementation
    parent obj can reference a child obj...
    Interfacea Ia = new derivedclass();
    (parent class obj can point to a child class)
    cannot create an instance of an interface
  21. 21Explicit Interface Implementation2 interfaces with same method inherited, then in derived class:
    void I1.InterfaceMethod();
    void I2.InterfaceMethod();
    if you want 1 of the methods to be default then one of them is
    public void InterfaceMethod()
    the other can be called by type casting:
    ((I2)p).InterfaceMethod();
  22. 22Abstract ClassesUsed as base classes thus cannot be sealed
    all members within abstract class marked as abstract must have implementations in the derived class -- ok not tohave any abstract members
    a class that inherits an abstract class and does not implement then it must be marker as abstract
  23. 23Abstract Classes Vs. Interfaces1.abstract can have implementations, interfaces cannot
    2.abstract can have fields, interfaces no
    3.interfaces can only inherit from other interfaces, abstract class can inherit from another abstract class and interface
    4.abstract class members can have access modifiers, interfaces cannot
  24. 24problem with multiple class inheritance (Ofcourse c sharp does not support this)Diamond proble -- class d inherits from class b or c?
  25. 25Multiple class inheritance using interfacesMultiple class inheritance using interfaces
  26. 26Multicast DelegatesMulticast Delegates
  27. 27Handling ExceptionsHandling Exceptions

Informationen

Beschreibung
Karteikarten am C Sharp, erstellt von mangat.paul am 03/12/2014.
Erstellt von
mangat.paul
Aufrufe
23
Bewertung
Durchschnittliche Bewertung 5,0 von 5 (1 Bewertung)

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck