Solved Compiler Error CS0050 (C#)

silentwolf

Active member
Local time
Today, 02:02
Joined
Jun 12, 2009
Messages
644
Hi guys,

I am running into a problem in C# and hope someone could let me know how I would need to change following Code.

incosistent accessability: return type List<Person> GetPeople is less accessable then method 'DataAccess'.GetPeople.

This is a code Tim Corey did profide on a You Tube Tutorial. Unfortunatelly I get the Error but can't seam to work out where I would need to change the accessibility.

So maybe someone could tell me please?

Code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;

namespace SonnenhausCSharpAndSQLServer
{
  public class DataAccess
  {
    public List<Person> GetPeople(string lastName)
    {
      using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("Sonnehaus")))
      {
        var output = connection.Query<Person>($"SELECT * FROM Employees WHERE SurName = '{ lastName}'").ToList();
        return output;
      }
    }
  }
}

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SonnenhausCSharpAndSQLServer
{
  public partial class Dashboard : Form
  {
    List<Person> people = new List<Person>();

    public Dashboard()
    {
      InitializeComponent();
      UpdateBinding();
    }

    private void UpdateBinding()
    {
      peopleFoundListbox.DataSource = people;
      peopleFoundListbox.DisplayMember = "FullInfo";
    }

    private void searchButton_Click(object sender, EventArgs e)
    {
      DataAccess db = new DataAccess();
      people = db.GetPeople(lastNameText.Text);
      UpdateBinding();
    }
  }
}

Many thanks

Albert
 
I noticed you have yet to receive a reply to your question. I'm not surprised, because I doubt if there's many people here that have experience with the c sharp language, but you never know! Hence I am bumping it up the list so that it gets another look. Best of luck.
 
So maybe someone could tell me please?
That's hard because the code you quoted shows only part of the problem.
Here is a hint:
Look at your definition of the Person class. I guess, you defined the class as private or protected, but you use it (indirectly) as return type of your public GetPeople method. - This cannot work because callers of GetPeople may receive a type they don't know anything about.
 
Hi guys,

sorry was not here but yes I did manage to get it to work!
@sonic8,
Yes that was the issue the Class was not defined as public but did not spot it at first.

Many thanks for replies and hints!
Cheers
 

Users who are viewing this thread

Back
Top Bottom