C# - 不一致的可访问性:返回类型列表比方法更难访问

时间:2017-01-16 22:32:04

标签: c#

namespace BusinessLayer
{
    public class StudentBusinessLayer
    {
        public List<Student> getStudents(string storedProcedure)
        {
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
            {
                List<Student> students = new List<Student>();
                SqlCommand comm = new SqlCommand(storedProcedure, conn);
                comm.CommandType = CommandType.StoredProcedure;
                conn.Open();
                SqlDataReader rdr = comm.ExecuteReader();
                while (rdr.Read())
                {
                    Student s = new Student();
                    s.id = Convert.ToInt32(rdr["id"]);
                    s.Name = rdr["Name"].ToString();
                    s.TotalMarks = Convert.ToInt32(rdr["TotalMarks"]);

                    students.Add(s);
                }
                return students;
            }
        }
    }
}

enter image description here

2 个答案:

答案 0 :(得分:2)

您的Student课程似乎不是public,请让public修正您的错误。

答案 1 :(得分:0)

你的回归是错误的:

namespace BusinessLayer
{
    public class StudentBusinessLayer
    {
        public List<Student> getStudents(string storedProcedure)
        {
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
            {
                List<Student> students = new List<Student>();
                SqlCommand comm = new SqlCommand(storedProcedure, conn);
                comm.CommandType = CommandType.StoredProcedure;
                conn.Open();
                SqlDataReader rdr = comm.ExecuteReader();
                while (rdr.Read())
                {
                   Student s = new Student();
                   s.id = Convert.ToInt32(rdr["id"]);
                   s.Name = rdr["Name"].ToString();
                   s.TotalMarks = Convert.ToInt32(rdr["TotalMarks"]);

                    students.Add(s);
                }
            }

            return students;
        }
    }
}