Skip to content

Instantly share code, notes, and snippets.

@Tesla9527
Created September 16, 2015 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tesla9527/7325c14b9e3e57f77a30 to your computer and use it in GitHub Desktop.
Save Tesla9527/7325c14b9e3e57f77a30 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public class Student
{
private int _id;
private string _name;
public string Email { get; set; }
public int Id
{
get { return _id; }
set
{
if (value <= 0)
{
throw new Exception("Student Id cannot be negative");
}
_id = value;
}
}
public string Name
{
get { return _name; }
set
{
if (string.IsNullOrEmpty(value))
{
throw new Exception("Student name cannot be Null or Empty");
}
_name = value;
}
}
}
public class Program
{
static void Main(string[] args)
{
Student S1 = new Student();
S1.Id = -101;
S1.Name = "Tesla";
S1.Email = "tesla@gmail.com";
Console.WriteLine("The student info is: Id = {0}, Name = {1}, Email= {2}", S1.Id, S1.Name, S1.Email);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment