Jump to content
Xtreme .Net Talk

Item does not contain definition and no extension method


Recommended Posts

Posted

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.

 

 

// 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");
       }
   }
}

  • Administrators
Posted

In the line of code

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

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...