小问题

lannet 2006-10-30 09:09:51
我现在还在学习C#中 `看到红皮书的第11章 `
做到后面的练习中有个地方想问
public class Person
{
private string name;
private int age;

public string Name
{
get
{
return name;
}
set
{
name =value ;
}
}

public int Age
{
get
{
return age ;
}
set
{
age = value;
}
}
public Person(string newName,int newAge)
{
Name = newName;
Age = newAge;
}
}

public class people :DictionaryBase
{
public void Add(string personID,Person newperson)
{
Dictionary.Add(personID, newperson);
}

public void Remove(string personID)
{
Dictionary.Remove(personID);
}

public people()
{
}

public Person this[string personID]
{
get
{
return (Person)Dictionary[personID];
}
set
{
Dictionary[personID] = value;
}
}
}

class Program
{
static void Main(string[] args)
{
people peopleTOP = new people();
peopleTOP.Add("john", new Person("john",19));
peopleTOP.Add("lannet",new Person("lannet",20));
foreach (DictionaryEntry mypeople in peopleTOP)
{
//为什么这里用下面的这种方法就可以而我用
//Console.WriteLine(((Person )mypeople .Value ).Name,((Person )mypeople .Value ).Age);
// 不会产生问题却不能显示出age的值?
Console.WriteLine(((Person )mypeople .Value ).Name);
Console .WriteLine (((Person )mypeople .Value ).Age);
}
}
}
...全文
128 2 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lannet 2006-10-30
  • 打赏
  • 举报
回复
追问`

为什么一定要有个“”内容`而不能直接打出?

是不是Console.WriteLine 里面有2个参数以上的都要用这样`?
feiyun0112 2006-10-30
  • 打赏
  • 举报
回复
Console.WriteLine("Name={0},Age={1}", ((Person )mypeople .Value ).Name,((Person )mypeople .Value ).Age);

*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
相关推荐
发帖
C#

10.9w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
帖子事件
创建了帖子
2006-10-30 09:09
社区公告

让您成为最强悍的C#开发者