Upc Pre Si730 Csharp Oop Features - v1
Upc Pre Si730 Csharp Oop Features - v1
Upc Pre Si730 Csharp Oop Features - v1
UNIDAD 1 | OVERVIEW
C# OOP FEATURES
INTRO
CLASSES & CONSTRUCTORS
PROPERTIES
STATIC MEMBERS, CONSTANTS, METHODS
ANONYMOUS & NULLABLE TYPES
STRUCTURES & ENUMERATIONS
INHERITANCE
INTERFACES, ABSTRACT & SEALED CLASSES
Intro
INTRO
CLASSES & CONSTRUCTORS
PROPERTIES
STATIC MEMBERS, CONSTANTS, METHODS
ANONYMOUS & NULLABLE TYPES
STRUCTURES & ENUMERATIONS
INHERITANCE
INTERFACES, ABSTRACT & SEALED CLASSES
class Keyword
Se define una clase con la instrucción class. La clase puede tener
miembros. Se delimita con llaves.
class Program
{
static void Main(string[] args)
{
Student student = new Student();
}
}
Constructores
public Student()
{
_firstName = string.Empty;
_lastName = string.Empty;
}
public Student()
{
_firstName = string.Empty;
_lastName = string.Empty;
}
INTRO
CLASSES & CONSTRUCTORS
PROPERTIES
STATIC MEMBERS, CONSTANTS, METHODS
ANONYMOUS & NULLABLE TYPES
STRUCTURES & ENUMERATIONS
INHERITANCE
INTERFACES, ABSTRACT & SEALED CLASSES
Properties
INTRO
CLASSES & CONSTRUCTORS
PROPERTIES
STATIC MEMBERS, CONSTANTS, METHODS
ANONYMOUS & NULLABLE TYPES
STRUCTURES & ENUMERATIONS
INHERITANCE
INTERFACES, ABSTRACT & SEALED CLASSES
Static methods
int givenNumber = 4;
Console.WriteLine(Math.Sqrt(givenNumber));
Constants
static GivenValueHolder ()
{
_givenValue = 128;
}
}
Extension methods
class Program
{
static void Main(string[] args)
{
string word = "developer"
.FirstLetterUpperCase();
Console.WriteLine(word);
Console.ReadKey();
}
}
AGENDA
INTRO
CLASSES & CONSTRUCTORS
PROPERTIES
STATIC MEMBERS, CONSTANTS, METHODS
ANONYMOUS & NULLABLE TYPES
STRUCTURES & ENUMERATIONS
INHERITANCE
INTERFACES, ABSTRACT & SEALED CLASSES
Anonymous classes
if(number.HasValue)
{
Console.WriteLine(number.Value);
}
else
{
Console.WriteLine("number is null");
}
AGENDA
INTRO
CLASSES & CONSTRUCTORS
PROPERTIES
STATIC MEMBERS, CONSTANTS, METHODS
ANONYMOUS & NULLABLE TYPES
STRUCTURES & ENUMERATIONS
INHERITANCE
INTERFACES, ABSTRACT & SEALED CLASSES
Structures
Son value types, mientras que las clases son reference types.
Pueden tener fields, methods y constructors.
Se declaran con el struct keyword.
public struct Time
{
private int _hours, _minutes, _seconds;
Acceso a structures.
Console.ReadKey();
}
Structures
Console.WriteLine(monday); // Monday
Console.WriteLine((int)monday); // 0
Console.ReadKey();
}
Enumerations
INTRO
CLASSES & CONSTRUCTORS
PROPERTIES
STATIC MEMBERS, CONSTANTS, METHODS
ANONYMOUS & NULLABLE TYPES
STRUCTURES & ENUMERATIONS
INHERITANCE
INTERFACES, ABSTRACT & SEALED CLASSES
Inheritance
Se utiliza el as keyword.
Ocultar método de clase padre con otra versión usando new keyword.
public class Writer
{
public string FileName { get; set; }
INTRO
CLASSES & CONSTRUCTORS
PROPERTIES
STATIC MEMBERS, CONSTANTS, METHODS
ANONYMOUS & NULLABLE TYPES
STRUCTURES & ENUMERATIONS
INHERITANCE
INTERFACES, ABSTRACT & SEALED CLASSES
Definir interfaz
Console.ReadKey();
}
}
Abstract classes
}
RESUMEN
Recordemos
C# ofrece soporte para el paradigma orientado a objetos.
Permite declarar clases que contienen members.
Las clases soportan single-inheritance, pero pueden
implementar múltiples interfaces.
Soporta method hiding, overriding.
Soporte abstract & sealed classes.
REFERENCIAS
Para profundizar
UPC
Universidad Peruana
de Ciencias Aplicadas
exígete, innova