Professional Documents
Culture Documents
Estudo CSharp - Conceitos Colocar Curriculo
Estudo CSharp - Conceitos Colocar Curriculo
1 Namespace............................................................................................................................1
19 Classes...............................................................................................................................10
20 – Static and instance class members.................................................................................12
21 Inheritance........................................................................................................................14
22 Method hiding...................................................................................................................18
23 Polymorphism...................................................................................................................20
Method overloading...............................................................................................................22
26 Properties / encapsulation................................................................................................22
27 Properties..........................................................................................................................23
28 Structs...................................................................................................................................24
29 Classes vs Structs...............................................................................................................25
30 Introduction to interfaces.................................................................................................28
31 Explicit interfaces implementation....................................................................................29
32 Abstract classes.................................................................................................................30
1 Namespace
3-4
6
7
Mas eh melhor usar convert pois dá exceção se não conseguir converter enquanto que ()
converte para o menor valor possível:
8
9
10
11
12
13
14
15
16
Instance method:
Static method:
Parameters
17
Reference:
Out parameters
Parameters with params keyword makes parameters optional:
Passando array
Params array sempre no final
18
19 Classes
Constructor, destructor and how to create class instance:
Default constructor in case only no constructor was provided. If a constructor was provided
then the default one does not work:
Using two constructors:
21 Inheritance
Multiple base classes is not supported
Class A has all the elements from class Employee and PartTimeEmployee
22 Method hiding
Using method from parent class in child class using base keyword:
The way of calling the hidden method is:
Even though the specialized methods from child classes hide the corresponding methods from
parent class, given that the object type is of parent class, the parent class method is called.
In order to get the results from the specialized methods from the child classes, use virtual
keyword in the method from parent class what will make it possible to override this method in
child classes:
The result is then
Method overloading
26 Properties / encapsulation
27 Properties
The property can have any name, but to make it simple give it the name of the field:
The syntax is like a public field:
28 Structs
29 Classes vs Structs
In the following example, both C1 and C2 will have the same name (i.e. Marry) as a class is a
reference type. While I and j which are value types will have different values (i=10, j=11).
30 Introduction to interfaces
The implementation of the interface methods is mandatory and the implanted methods must
have the same name and signature, otherwise a compile error will be issued.
32 Abstract classes
The main point is that an abstract class is like any other class, but it is incomplete (i.e. it may
contain abstract members, it does not contain fields), whence it cannot be instantiated.
Basic implementation:
33 Enums