Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error saying system.void cannot be used from c# [closed]

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?

like image 906
Cybercop Avatar asked Feb 10 '26 20:02

Cybercop


1 Answers

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.

like image 89
Jon Skeet Avatar answered Feb 12 '26 14:02

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!