c#如何取字典表的值,C#,如何从字典中的对象中获取值

// If anyone can help me I'd appreciate it.

// More than happy to buy you a coffee. Just give me your email address.

// Not looking for any free information.

// used this to create the student object with no issues.

public Student(string first, string last)

{

FirstName = first;

LastName = last;

}

// i've had no issues storing the object in this dictionary.

// used to add student to dictionary.

Student.current.Add(Student.student_ID, added);

// actual dictionary.

public static Dictionary current = new Dictionary();

// Previously had Students being stored in list with no issues when grabbing values.

// Now I want to print each student stored in the dictionary with all values //pertaining to each student.

public static void printStudents()

{

foreach (KeyValuePair pair in current)

{

Console.WriteLine("{0}, {1}", pair.Key, Student.FirstName);

Console.WriteLine("{0}, {1}", pair.Key, Student.LastName);

}

}

// this is my old code had no issues.

/*

foreach (var listing in current)

{

Console.WriteLine("\nStudent ID: {0}", listing.ID);

Console.WriteLine("First Name: {0}", listing.FirstName);

Console.WriteLine("Last Name: {0}\n", listing.LastName);

}

*/

What I have tried:

I feel like I've tried everything.

Maybe in dictionaries, data can't be extracted directly ?

解决方案Console.WriteLine("{0}, {1}", pair.Key, pair.Value.FirstName);

Console.WriteLine("{0}, {1}", pair.Key, pair.Value.LastName);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值