Last active
October 1, 2016 07:42
-
-
Save Abiwax/d6105b568c76ff49b396ba728cb86f73 to your computer and use it in GitHub Desktop.
Example
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
public class Student{ | |
public Dictionary<string, object> CustomProperties = | |
new Dictionary<string, object>(); | |
} | |
public class Program | |
{ | |
public void FindName(List<Student> student, string name) | |
{ | |
List<Student> names = student; | |
string studentname = name; | |
foreach (Student currentSt in names) | |
{ | |
foreach (var prop in currentSt.CustomProperties) | |
{ | |
if (prop.Key == "Name" && Convert.ToString(prop.Value) == studentname) | |
{ | |
Console.WriteLine("I found " + prop.Value); | |
} | |
} | |
} | |
} | |
public void FindFailed(List<Student> student) | |
{ | |
List<Student> names = student; | |
foreach (Student currentSt in names) | |
{ | |
foreach (var prop in currentSt.CustomProperties) | |
{ | |
if ((prop.Key == "Java" && Convert.ToInt32(prop.Value) < 50) || (prop.Key == "Statistics" && Convert.ToInt32(prop.Value) < 50)) | |
{ | |
Console.WriteLine("The failed grades includes: "); | |
Console.WriteLine(prop); | |
} | |
} | |
} | |
Console.ReadLine(); | |
} | |
public void findAgeAverage(List<Student> student) | |
{ | |
int sum = 0; | |
List<Student> names = student; | |
foreach (Student currentSt in names) | |
{ | |
foreach (var prop in currentSt.CustomProperties) | |
{ | |
if (prop.Key == "Age") | |
{ | |
sum += Convert.ToInt32(prop.Value); | |
} | |
} | |
} | |
decimal average = (decimal)sum / names.Count; | |
Console.WriteLine("The average age: "+ average); | |
Console.WriteLine("end"); | |
Console.ReadLine(); | |
} | |
static void Main(string[] args) | |
{ | |
List<Student> lstStudents = new List<Student>(); | |
Student objStudent = new Student(); | |
objStudent.CustomProperties.Add("Name", "Tom"); | |
objStudent.CustomProperties.Add("Age", 30); | |
objStudent.CustomProperties.Add("Java", 40); | |
objStudent.CustomProperties.Add("Statistics", 80); | |
lstStudents.Add(objStudent); | |
objStudent = new Student(); | |
objStudent.CustomProperties.Add("Name", "Sreejata"); | |
objStudent.CustomProperties.Add("Age", 26); | |
objStudent.CustomProperties.Add("Java", 87); | |
objStudent.CustomProperties.Add("Statistics", 73); | |
lstStudents.Add(objStudent); | |
objStudent = new Student(); | |
objStudent.CustomProperties.Add("Name", "Rajat"); | |
objStudent.CustomProperties.Add("Age", 25); | |
objStudent.CustomProperties.Add("Java", 80); | |
objStudent.CustomProperties.Add("Statistics", 33); | |
lstStudents.Add(objStudent); | |
objStudent = new Student(); | |
objStudent.CustomProperties.Add("Name", "Anita"); | |
objStudent.CustomProperties.Add("Age", 20); | |
objStudent.CustomProperties.Add("Java", 77); | |
objStudent.CustomProperties.Add("Statistics", 82); | |
lstStudents.Add(objStudent); | |
objStudent = new Student(); | |
objStudent.CustomProperties.Add("Name", "Steve"); | |
objStudent.CustomProperties.Add("Age", 19); | |
objStudent.CustomProperties.Add("Java", 60); | |
objStudent.CustomProperties.Add("Statistics", 90); | |
lstStudents.Add(objStudent); | |
Program pr = new Program(); | |
Console.WriteLine("Please input the name you want to search for:"); | |
string name = Console.ReadLine(); | |
pr.FindName(lstStudents, name); | |
pr.FindFailed(lstStudents); | |
pr.findAgeAverage(lstStudents); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment