Tohron
Tohron

Reputation: 55

Can't Access Property of Public Interface

I've defined a simple interface:

public interface Categorizable {

    string Category { get; set; }
}

Elsewhere, I try to use it in a function:

public void Add(Categorizable item)
{
    string cat = item.Category;
}

However, Visual Studio tells me "Categorizable does not contain a definition for Category". How do I fix this so that Category can be used as an accessible property?

Upvotes: 1

Views: 858

Answers (1)

TheGeneral
TheGeneral

Reputation: 81473

  1. Interfaces should really have an I in front of them i. ICategorizable, its very common and a standard for C#.
  2. Check you haven't declared a class with the same name.
  3. Check you haven't declared your interface somewhere else.
    • If this is coming from a class library, check you are actually using the correct version, and its builds with your project.

Other than this, there isn't much else that can go wrong. This is how interfaces work (without deviation).

Upvotes: 2

Related Questions