利用Dictionary<TKey,TValue>查找多个城市的电话号码区号,查找并输出某个区号属于哪个城市!
1 要有菜单,分别为:显示全部信息 增加 删除 修改 查询 退出
2 在增加 修改 删除时,要先查询是否存在对应记录
3 要有属性,构造方法的应用。
4 重写ToString 方法用于显示内容。
5.代码最好带注释
------解决方案--------------------
你真牛
------解决方案--------------------
...........作业自己写比较好 不会的地方再来问嘛
------解决方案--------------------
利用Dictionary<TKey,TValue>查找多个城市的电话号码区号,查找并输出某个区号属于哪个城市!
1 要有菜单,分别为:显示全部信息 增加 删除 修改 查询 退出
2 在增加 修改 删除时,要先查询是否存在对应记录
3 要有属性,构造方法的应用。
4 重写ToString 方法用于显示内容。
5.代码最好带注释
给你扔个思路吧,代码真心懒得写。
a.首先看完需求,在 3 4 上说明需要声明自定义类型
b.其次,有删除 修改等操作,并且需要用到散列表这样的数据结构,所以可以认为Dictionary<>的key为唯一标识(推荐使用GUID或者当前时间毫秒或DateTime Ticks值),Value为a所声明的类型实例
c.如果需要持久化数据,那就需要用到文件或者数据库存储对象信息(或序列化后的对象信息)
d.涉及到的属性、构造方法、重写,上过课基本都会。
其余的没什么可说的了。
------解决方案--------------------
有没有发现你添加了两个北京?
quhao s2 = new quhao("北京", "010");
quhao s4 = new quhao("北京", "010");
出现这个错误的原因时Dictionary的键是不允许重复的。。。比如你把上面两条中任何一条中的010改成110
就没问题了。。
从 arr.Add(s0.tel, s0); 可以看出 你把电话作为键了 所以电话不要重复
------解决方案--------------------
24L帮你写的啊?恭喜你完成作业了。。。自己慢慢调试调试看看有没有bug吧 也是个学习的过程
------解决方案--------------------
帮一个大四的学姐做毕业设计,顺便作为暑假去找实习的一个作品吧,尽量做好些,加油LZ,相信你自己,可以的,我也加油,希望能找个好的实习...
------解决方案--------------------
给个提示,全国省市县乡的数据有45xxx多条,如果全部放到Dictionary里面,初始的时候得建够容量。
------解决方案--------------------
- C# code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.Serialization;namespace ConsoleApplication3{ [DataContract] public class CityInfo { [DataMember] public string CityId { get; set; } [DataMember] public string CityName { get; set; } [DataMember] public string CityAreaNum { get; set; } } public enum InitializeType : int { GUI = 0, CommandLine = 1 } public enum CityInfoPropertyType : int { CityId = 0, CityName = 1, CityAreaNum } public interface IControl { Dictionary<string, CityInfo> DictionaryStore { get; } string Add(CityInfo info); List<string> Add(List<CityInfo> infos); string Delete(CityInfo info); List<string> Delete(List<CityInfo> infos); string Modify(CityInfo info); List<string> Modify(List<CityInfo> infos); CityInfo Exists(CityInfoPropertyType type, string value); } public abstract class BaseControl : IControl { public abstract string Add(CityInfo info); public abstract Dictionary<string, CityInfo> DictionaryStore { get; } private List<string> LoopDo(Func<CityInfo, string> func, List<CityInfo> infos) { List<string> results = new List<string>(); foreach(CityInfo info in infos) { string tmp = func(info); if (!string.IsNullOrEmpty(tmp)) { results.Add(tmp); } } return results; } public virtual List<string> Add(List<CityInfo> infos) { return LoopDo(Add, infos); } public abstract string Delete(CityInfo info); public virtual List<string> Delete(List<CityInfo> infos) { return LoopDo(Delete,infos); } public abstract string Modify(CityInfo info); public List<string> Modify(List<CityInfo> infos) { return LoopDo(Modify,infos); } public CityInfo Exists(CityInfoPropertyType type, string value) { throw new NotImplementedException(); } } public class CommandLineControl : BaseControl { public override string Add(CityInfo info) { throw new NotImplementedException(); } public override Dictionary<string, CityInfo> DictionaryStore { get { throw new NotImplementedException(); } } public override string Delete(CityInfo info) { throw new NotImplementedException(); } public override string Modify(CityInfo info) { throw new NotImplementedException(); } } public class PhoneNote { public PhoneNote(InitializeType type) { } }}