永发信息网

c#的泛型集合问题

答案:1  悬赏:70  手机版
解决时间 2021-05-07 12:48

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace WindowsApplication1
{
public class Employee:IComputeProfit
{
string name;
Dictionary<string, Customer> dic = new Dictionary<string, Customer>();

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

public bool AddCustomer(Customer c)
{
dic.Add(c.Name, c);
return true;
}

public void Print()
{
try
{
FileStream fs = new FileStream(string.Format("{0}.txt", this.Name), FileMode.Create);
StreamWriter writer = new StreamWriter(fs);
writer.WriteLine("{0}的客户列表,客户的个数为:{1}", this.Name, dic.Count);
writer.WriteLine("-------------------------------------------------------");
foreach (Customer c in dic.Values)
{
writer.WriteLine("客户姓名:{0}", c.Name);
writer.WriteLine("客户类型:{0}", c.Leval);
}
writer.Close();
fs.Close();
}
catch
{

}
}

public Customer GetCustomerByName(string customerName)
{
if (dic.ContainsKey(customerName))
return dic[customerName];
else
return null;
}


#region IComputeProfit 成员

public decimal ComputeProfit()
{
decimal d = 115;
d = d + 100 * dic.Count;
return d;
}

#endregion
}
}

---------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;

namespace WindowsApplication1
{
public enum CustomerType
{
黄金,白金,钻石
}

public class Customer:IComputeProfit
{
string name;
CustomerType leval;

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


#region IComputeProfit 成员

public decimal ComputeProfit()
{
switch (this.Leval)
{
case CustomerType.黄金:
return 125.35;
break;
case CustomerType.白金:
return 175;
break;
case CustomerType.钻石:
return 250;
break;
}
}

#endregion
}
}

----------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;

namespace WindowsApplication1
{
public static class Manager
{
static Dictionary<string, Employee> dic = new

Dictionary<string, Employee>();

public static Dictionary<string, Employee> Dic
{
get { return Manager.dic; }
}

public static bool AddEmployee(Employee e)
{
dic.Add(e.Name, e);
return true;
}

public static bool Service(string employeeName,Customer c)
{
if (dic.ContainsKey(employeeName))
{
dic[employeeName].AddCustomer(c);
return true;
}
else
return false;

}

public static Employee GetEmployeeByName(string employeeName)
{
if (dic.ContainsKey(customerName))
return dic[customerName];
else
return null;
}
}
}

我现在就是不懂到底这个键值对的搜索问题. 尤其是这个employeeName这个键 根本就是没声明过 但是ContainsKey又是如何去查询、? 可能我脑子有点迷糊。 希望有个明白人 帮我详细讲讲泛型集合问题 3Q

最佳答案
employeeName 这个键 是在方法参数里边声明的。
public static bool Service(string employeeName ,Customer c)

在这里声明的。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
移动GPRS一个月怎么开两次
七个月宝宝的正常体重
又什么办法能确定他是不是对你有感觉 可是我
童话故事不少于300字,不要太多的
朋友快过生日了。想发条短信过去。不知道发什
从张家口坐车到邯郸多少钱啊?
权家塬村村地址在哪,我要去那里办事
喜欢一个人是不是要对她实话不能撒谎为什么?
QQ三国XS點心法
为什么凉水杯壁上有水泡而热水的上面就没有呢
动感地带手机SIM卡最多能存多少电话号码?
人为什么会口吃结巴?
脑筋急转弯,天天去看病的人是谁?
直角三角的定律和计算公式?开平方怎么开
烽火战国的蓝钻有啥特权?
推荐资讯
我朋友这算是喜欢麽?
精灵解说的博客地址是什么?
鲁盛装饰材料批发这个地址在什么地方,我要处
我的QQ号真奇怪
09年四川成人考试分数查询的短消息查询号码是
摩尔庄园的摩罗云海里怎么找不到珍珠
QQ飞车中砸多少蛋可以获得更名卡?
雷柏鼠标怎么拆开图解,怎么拆开鼠标?(鼠标
人要怎样戒酒?
DNF找回装备需要一个工作日是多久、能找回吗
现在有几个25级的QQ号?
细胞融合技术优点,区别于植物体细胞杂交的
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?