jusapi

POO02

Jul 22nd, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace POO
  6. {
  7.     class Persona
  8.     {
  9.         private string Nombre;
  10.         //private string Apellido;
  11.         public string Apellido { get; set; }
  12.  
  13.         private int _edad;
  14.         public int Edad
  15.         {
  16.            get { return this._edad; }
  17.            set {
  18.                 if (value > 0)
  19.                 {
  20.                     this._edad = value;
  21.                 }
  22.             }
  23.         }
  24.  
  25.         // Metodos Modificadores/Analizadores
  26.         // Metodo SET - Nombre
  27.         public void setNombre(string _nom)
  28.         {
  29.             this.Nombre = _nom;
  30.         }
  31.         // Método GET - Nombre
  32.         public string getNombre()
  33.         {
  34.             return this.Nombre;
  35.         }
  36.  
  37.         // Constructor vacío
  38.         public Persona()
  39.         {
  40.             Console.WriteLine("Se creó el objeto ...");
  41.         }
  42.         // Constructor con parámetros
  43.         public Persona(string _nombre, string _apellido, int _edad)
  44.         {
  45.             this.Nombre = _nombre;
  46.             this.Apellido = _apellido;
  47.             this.Edad = _edad;
  48.         }
  49.  
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment