CanVote
方法:如果年龄大于等于18岁,则返回true。
该类的构造函数将所有属性赋予默认值。
我将对象添加到哈希表中,以人名为键。
我需要遍历哈希表对象,打印出姓名和此人是否有投票权。
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();
}
}
}
string name; string dob; int age;
- MethodMan