C Sharp

Description

Flashcards on C Sharp, created by mangat.paul on 03/12/2014.
mangat.paul
Flashcards by mangat.paul, updated more than 1 year ago
mangat.paul
Created by mangat.paul over 10 years ago
18
0
1 2 3 4 5 (1)

Resource summary

Question Answer
main features of a static class Contains only static members.Cannot be instantiated.Is sealed.Cannot contain Instance Constructors.
public The 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.
private The 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.
protected The 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
internal The 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
protected internal The 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
method hiding use 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();
polymorphism polymorphism 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...
method parameters 4 types 1.value 2.reference 3.out 4.parameter arrays
methods passing a parameter by value vs. reference value 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
out parameters used if multiple values need to be returned from a method int 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)
parameter arrays paramsmeth(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
private fields naming convention use an underscore before the variable name private int _test;
"value" keyword public int id; get{} set{ if (value <0) error else this._id = value } your variable is passed into value
properties we 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
using properties for encapsulation private int _i; public int i; get{} set{}
public string city {get; set;} shortcut method if no validation needed (private fields are created for you in background)
object initializer syntax customer cust1 = customer { Id =10, Name = Costco };
struct 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
Interfaces Naming: 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
Explicit Interface Implementation 2 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();
Abstract Classes Used 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
Abstract Classes Vs. Interfaces 1.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
problem with multiple class inheritance (Ofcourse c sharp does not support this) Diamond proble -- class d inherits from class b or c?
Multiple class inheritance using interfaces
Multicast Delegates
Handling Exceptions
Show full summary Hide full summary

0 comments

There are no comments, be the first and leave one below:

Similar

Programming in C# Exam 70-483 Q&A
dino.in
Programming in C# Certification 70-483 Q&A
Khrystal Colon
OCR AS Biology - Enzymes
Chris Osmundse
Physics equations GCSE
Mia Jones
Maths GCSE - What to revise!
livvy_hurrell
Health and Social Care
Kelsey Phillips
Biology B1
Kelsey Phillips
NSI Test First day
brahim matrix
2PR101 1. test - 2. část
Nikola Truong
A child with a stiff neck
fatima alkhateeb