Method CanVote
returns true if Age >=18.
Constructor of the class assigns default values to all properties.
I added the objects to a hashtable with key as Person Name.
I need to iterate through the hashtable object to print Name and whether the person can vote or not.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;*/
namespace HashTable
{
class theClass
{
string name;
string dob;
int age;
public theClass(string name,int age, string dob)
{
this.name = name;
this.age = age;
this.dob=dob;
}
public static string canvote(int age)
{
if (age >= 18)
return "Can Vote";
else
return "Cnnot Vote";
}
}
public class Solution
{
public static void Main()
{
Hashtable h = new Hashtable();
theClass object1 = new theClass("John",16,"Chennai");
theClass object2 = new theClass("Smita",22, "Delhi");
theClass object3 = new theClass("Vincent",25, "Banglore");
theClass object4 = new theClass("Jothi", 10, "Banglore");
h.Add("John", object1);
h.Add("Smita", object2);
h.Add("Vincent", object3);
h.Add("Jothi", object4);
Console.WriteLine("df");
Console.WriteLine(h.canvote());
Console.ReadKey();
}
}
}