I'm a new trying to understand classes and how classes work. I'm building a small console program and am currently working on my 'class.cs' file which I titled 'LineItem.cs' as it will handle the line items on the receipt that I am trying to have my console application generate.
PROBLEM: Member 'A070_Classes_CashRegister.Program.receipt()' cannot be accessed with an instance reference; qualify it with a type name instead. (Error Line: #21/Column #13)
I thought that i had done this on line #21 when I entered 'this.color = price;
Code:
using System;
namespace a070___Classes___CashRegister
{
class LineItem // Class name is singular
// receipt might be better name for this class?
{
/// Class Attributes
private String product; // constructor attribute
private String description;
private String color;
private double price;
private Boolean isAvailable;
// constructor called to make object => LineItem
public LineItem(String product, String description, String color, int price, Boolean isAvailable)
{
this.product = product;
this.description = description;
this.color = color;
this.price = price;
this.isAvailable = isAvailable;// might want to do an availability check
}
//Getters
public String GetProduct() {return product;}
public String GetDescription(){return description;}//Send description
public String GetColor() {return color;}
//Setter
public void SetColor(string color)//we might want to see it in other colors if is option
{ this.color = color; } //changes object color
}
}
Main file which will call the class:
using System;
namespace a070___Classes___CashRegister
{
class Program
{
static void receipt()
{
//stuff goes here - we call various instances of the class to generate some receipts
}
static void Main(string[] args)
{
//Program CashRegister = new Program();
//CashRegister.receipt();
//Program CashRegister = new Program();
//CashRegister.receipt();
receipt();// Don't need to instantiate Program, console applications framework will find the static function Main
//unless changed your project properties.
//Since reciept is member od Program and static too, you can just call it directly, without qualification.
}
}
}