user1765862
user1765862

Reputation: 14185

must declare a body because it's not marked abstract

I have interface

INews.cs
public interface INews{
   int Id {get; set;}
   string Name {get; set;}
   void Add(News news);
   void Remove(News news);
}

and I have News.cs which implements that interface

public class News : INews {
  public int Id {get; set;}
  public string Name {get; set;}
  public void Add(News news);
  public void Remove(News news);

}

on compile, I have the following message must declare a body because it's not marked abstract

is that mean that I should declare body inside the constructor of News class?

Upvotes: 0

Views: 44278

Answers (5)

Abdullah Akhtar
Abdullah Akhtar

Reputation: 558

I hope this works.

The body Must be included within flower brackets

Sol:

public void Add(News news)
{

}

public void Remove(News news)
{

}

There should be a declaration of any abstract class

Upvotes: 0

Jens Kloster
Jens Kloster

Reputation: 11287

Its your implementation

public class News: INews
{
  public int Id {get; set;}
  public string Name {get; set;}
  public void Add(News news); //<-- invalid
  public void Remove(News news); //<-- invalid
}

should at least be

public class News: INews
{
  public int Id {get; set;}
  public string Name {get; set;}
  public void Add(News news){

  }

  public void Remove(News news){

  }
}

Upvotes: 9

Nate
Nate

Reputation: 91

the method must declare a body if its not an abstract class

public void Add(News news)
{

}

public void Remove(News news)
{

}

Upvotes: 3

Oded
Oded

Reputation: 499272

It means that you have not make your News class an abstract class.

In a class that is not an abstract class, the methods must have implementations, not just declarations.

Upvotes: 4

nvoigt
nvoigt

Reputation: 77354

Your functions need bodies:

public void Add(News news)
{

} 

public void Remove(News news)
{

}

Functions without bodies are only allowed in abstract classes.

Upvotes: 9

Related Questions