Created
September 16, 2015 03:34
-
-
Save Tesla9527/7325c14b9e3e57f77a30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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