I have a interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Guestbook.Models;
namespace Guestbook.Controllers
{
public interface IGuestbookRepository
{
IList<GuestbookEntry> GetMostRecentEntries();
GuestbookEntry FindById(int id);
IList<CommentSummary> GetCommentSummary();
Void AddEntry(GuestbookEntry entry);
}
}
and the implementation class looks like this
using System;
using System.Collections.Generic;
using System.Linq;
using Guestbook.Models;
namespace Guestbook.Controllers
{
public class GuestbookRepository : IGuestbookRepository
{
private readonly GuestbookContext _db = new GuestbookContext();
public void AddEntry(GuestbookEntry entry)
{
entry.DateAdded = DateTime.Now;
_db.Entries.Add(entry);
_db.SaveChanges();
}
}
when i type to compile it i get error saying System.void cannot be used from c# -- use typeof(void) to get the void type object.
What exactly is wrong that I'm doing? Can someone help me maybe?
This is the problem, in the interface declaration:
Void AddEntry(GuestbookEntry entry);
It should be:
void AddEntry(GuestbookEntry entry);
The first version refers to the System.Void type, which can't be used within C# (as per the error message). The second is the C# way of writing a method which no return value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With