注册 登录
编程论坛 C# 论坛

未能找到类型或命名空间名称“Student”(是否缺少 using 指令或程序集引用?

李曼1992 发布于 2015-12-03 20:27, 3184 次点击
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ch05.Examples
{
    class SortedDictionaryExample
    {
        StringBuilder sb = new StringBuilder();
        public SortedDictionaryExample()
        {
            SortedDictionary<int, Student> students = new SortedDictionary<int, Student>()
            {
                {2,new Student {Name="李四",Gender="男"}},
                {1,new Student {Name="张三",Gender="男"}},
                {3,new Student {Name="王五",Gender="男"}}
            };
            foreach(var v in students)
            {
                sb.AppendLine(string.Format("编号:{0}--姓名:{1},性别:{2}",v.Key,v.Value.Name,v.Value.Gender));
            }
        }
        public string GetOutPut()
        {
            return sb.ToString();
        }
    }
}
6 回复
#2
zj10217998792015-12-04 16:12
你应该将Student类型using进来你的这个.cs文件中,是using System.Student。
或者你将鼠标移到Student上,Student左下角会出现一个横线,然后点开它,点击第一个using,应该就可以了。
#3
李曼19922015-12-05 16:07
回复 2楼 zj1021799879
错误    1    命名空间“System”中不存在类型或命名空间名称“Student”。是否缺少程序集引用?   加了之后就出现着了。
#4
zj10217998792015-12-08 13:09
回复 3楼 李曼1992
哦哦,你的是命名空间找不到,之前没看清楚,我说的是对类型而言的。
嗯,是的,如果在不同命名空间下引用的话,是要将被引用的命名空间加进来。
不知道这次说的对不。
#5
李曼19922015-12-13 20:14
不是很懂您的意思,我没有在任何命名空间中定义student,它是system命名空间中原有的?可引用后就出现上边的错误了
#6
baisouy2015-12-14 15:09
典型的复制代码,不修改命名空间。
去坚持一下你的=student类的命名空间和你项目的命名空间一样吗?
#7
shghe2015-12-29 11:11
student应该是预定义好的一个类 或类型
1