-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperties.cs
56 lines (52 loc) · 1.3 KB
/
properties.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
namespace Properties
{
class Program
{
static void Main(string[] args)
{
Student c1 = new Student();
c1.SetId(101);
//Console.WriteLine("ID = {0] && nMAE = {1} && pASSmARK = {2}",c1.ID,c1.Name,c1.PasssMark);
Console.WriteLine("Student id = {0}",c1.GetId());
}
}
public class Student
{
private int _id;
private string _name;
private int _passsMark;
public void SetName(string Name)
{
if (string.IsNullOrEmpty(Name))
{
throw new Exception("Nmae cannot be null or empty");
}
this._name = Name;
}
public string GetName()
{
return string.IsNullOrEmpty(this._name) ? "No name" : this._name;
/*if (string.IsNullOrEmpty(this._name))
{
return "No Name";
}
else
{
return this._name;
}*/
}
public void SetId(int Id)
{
if (Id <= 0)
{
throw new Exception("Student Id cannot be negative");
}
this._id = Id;
}
public int GetId()
{
return this._id;
}
}
}