Skip to content

Instantly share code, notes, and snippets.

@Jore2
Created November 19, 2015 19:29
Show Gist options
  • Save Jore2/3d99f5a738398bb12bb7 to your computer and use it in GitHub Desktop.
Save Jore2/3d99f5a738398bb12bb7 to your computer and use it in GitHub Desktop.
01.Person
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _01.Person
{
public class Person
{
private string name;
private int age;
private string email;
public string Name
{
get
{
return this.name;
}
set
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException();
}
else
{
this.name = value;
}
}
}
public int Age
{
get
{
return this.age;
}
set
{
if (value <1 || value>100)
{
throw new ArgumentException("Age are ");
}
else
{
this.age = value;
}
}
}
public string Email
{
get
{
return this.email;
}
set
{
if (value != null && !value.Contains("@"))
{
throw new ArgumentException("Age are ");
}
else
{
this.email = value;
}
}
}
public Person(Person per):this(per.Name,per.Age,per.Email)
{
}
public Person (string name,int age,string email)
{
this.Name = name;
this.Age = age;
this.email = email;
}
public Person (string name,int age):this(name,age,null)
{
}
public override string ToString()
{
return string.Format("{0},{1},{2}",this.Name,Age,Email);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment