
[英]Can someone tell me how to access the DbContext from an ActionFilterAttribute method
[英]I've done this much, now can someone tell me how to take the records and put into a list so that i can access the records by choice?
namespace HW
{
class Program
{
struct Employee
{
int join_year;
int age;
string dept;
public void getval(int join_year, int age, string dept)
{
this.join_year = join_year;
this.age = age;
this.dept = dept;
}
public void showval()
{
Console.WriteLine("Joining year of Employee is: {0}", this.join_year);
Console.WriteLine("Age of Employee is: {0}", this.age);
Console.WriteLine("Department of Employee is: {0}", this.dept);
}
}
static void Main(string[] args)
{
Employee emp = new Employee();
Console.Write("Enter Joining Year: ");
int join_year = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Age: ");
int age = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Department: ");
string dept = Console.ReadLine();
emp.getval(join_year, age, dept);
emp.showval();
}
}
}
所以是的,基本上在这里我正在添加值并且它们也被打印出来。 现在我只想将这些记录添加到列表或数组中,以便我可以选择访问记录。
如果我理解正确,你想这样做。
List<string>() list = new List<string>();
for(int i = 0; i < 3; i++)
{
switch(i)
{
case 0: list.Add(join_year.ToString());
break;
case 1: list.Add(age.ToString());
break;
case 2: list.Add(dept);
break;
}
}
它非常简单,但可以完成这项工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.