Item does not contain definition and no extension method

rcanter

Newcomer
Joined
Sep 12, 2010
Messages
1
I am getting an error when trying to build. Error is that ReneApp.Item does not contain a definition for Item and no extension method 'Item' accepting a first argument could be found. Any assistance would be greatly appreciated. I am new to C# and this is my first try at a program.


Code:
// ReneApp.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ReneApp
{
    // Describes an item in the list:
    public struct Item
    {
        public string Status;       // Status of the item.
        public string Title;        // Title of the item.
        public string Series;       // Series the item is in.
        public string Author;       // Author of the item.
        public string Type;         // Type of item.
        public string Description;  // Description of item.

        public Item(string status, string title, string series, string author, string type, string description)
        {
            Status = status;
            Title = title;
            Series = series;
            Author = author;
            Type = type;
            Description = description;
        }
    }
    // Declare a type to process an item:
    public delegate void ProcessItemDelegate(Item item);

    // Maintains an item database.
    public class ItemDB
    {
        // List of all items in the database:
        ArrayList list = new ArrayList();

        // Add an item to the database:
        public void AddItem(string status, string title, string series, string author, string type, string description)
        {
            list.Add(new Item(status, title, series, author, type, description));
        }
        // Process items: 
        public void ProcessItem(ProcessItemDelegate processItem)
        {
            foreach (Item a in list)
            {
                if (a.Item)
                    processItem(a);
            }
        }
    }
}

// Using the Item class:
namespace ItemTestClient
{
    using ReneApp;

    class View
    {
        // Print the title of the item.
        static void PrintTitle(Item a)
        {
            Console.WriteLine("   {0}", a.Title);
        }

        // Execution starts here.
        static void Main()
        {
            ItemDB itemDB = new ItemDB();

            // Initialize the database with some items:
            AddItems(itemDB);

            // Print all the titles of items:
            Console.WriteLine("Item Titles:");
            // Create a new delegate object associated with the static 
            // method Test.PrintTitle:
            itemDB.ProcessItem(new ProcessItemDelegate(PrintTitle));
        }

        // Initialize the item database with some test items:
        static void AddItems(ItemDB itemDB)
        {
            itemDB.AddItem("Stock", "Dark Rival", "Masters of Time", "Brenda Joyce", "Book", "Time Travel");
            itemDB.AddItem("Stock", "Dark Prince", "Dark Series", "Christine Feehan", "Book", " ");
            itemDB.AddItem("Stock", "Shadow Game", "Ghost Walker", "Christine Feehan", "Book", " ");
            itemDB.AddItem("Stock", "The Quest", " ", "Lindsay McKenna", "Book", " ");
            itemDB.AddItem("Stock", "Rush Hour", "Rush Hour", "Jackie Chan", "Movie", "Action-Comedy");
            itemDB.AddItem("Stock", "The Long Kiss Goodnight", " ", "Samuel Jackson", "Movie", "Action");
            itemDB.AddItem("Stock", "Under Siege 2", "Under Siege", "Steven Seagal", "Movie", "Action");
            itemDB.AddItem("Stock", "Hostage", " ", "Bruce Willis", "Movie", "Action");
            itemDB.AddItem("Stock", "Tales of the Abyss", " ", " ", "Game", "Order of Lorelei");
            itemDB.AddItem("Loan", "The Curse of the Black Pearl", "Pirates of the Caribbean", "Johnny Depp", "Movie", " ");
            itemDB.AddItem("Wishlist", "Hidden Currents", "Drake Sisters", "Christine Feehan", "Book", "Book 7");
        }
    }
}
 
In the line of code
C#:
if (a.Item)
you are trying to access a member of the variable a with the name Item, the underlying structure Item doesn't expose a method or property called Item however.

The line of code
C#:
public Item(string status, string title, string series, string author, string type, string description)
defines a constructor for the Item structure, this is used when you create a new instance of Item and is never called directly however.
 
Back
Top