我想用C#写一个购物车的页,想创建一个购物车的模型类;
类大概是这样的,有一个Shoppings类(购物车组类)
在Shoppings类里再写一个Shopping类(购物车类)
在写Shoppings类的索引访问器类时出现了问题,问题如下:
可访问性不一致: 索引器返回类型“shoppingApplication.Shoppings.Shopping”比索引器“shoppingApplication.Shoppings.this[int]”的访问性低源码如下:
using System;namespace shoppingApplication
{
public class Shoppings
{
class Shopping
{
public static int shoppingCount=0;
private string shoppingName;
private int shoppingId;
private string articleName;
private double articlePrice;
Shopping()
{
this.shoppingName="";
this.shoppingid=Shopping.shoppingCount++;
this.articleName="";
this.articlePrice=0.0;
}
Shopping(string shoppingName)
{
this.shoppingName=shoppingName;
this.shoppingid=Shopping.shoppingCount++;
this.articleName="";
this.articlePrice=0.0;
}
Shopping(string shoppingName,string articleName,double articlePrice)
{
this.shoppingName=shoppingName;
this.shoppingid=Shopping.shoppingCount++;
this.articleName=articleName;
this.articlePrice=articlePrice;
}
public string ShoppingName
{
set
{
this.shoppingName=value;
}
get
{
return this.shoppingName;
}
}
public int ShoppingID
{
set
{
this.shoppingId=value;
}
get
{
return this.shoppingId;
}
}
public string ArticleName
{
set
{
this.articleName=value;
}
get
{
return this.articleName;
}
}
public double ArticlePrice
{
set
{
this.articlePrice=value;
}
get
{
return this.articlePrice;
}
}
} private Shopping[] listShoppings;
public Shoppings()
{
this.listShoppings=new Array[10];
}
public Shoppings(int index)
{
this.listShoppings=new Array[index];
}
public Shopping this [int index]
{
set
{
if(index>=0 || index<Shopping.shoppingCount)
this.listShoppings[index]=value;
}
get
{
if(index>=0 || index<Shopping.shoppingCount)
return this.listShoppings[index];
else
return new Shopping();
}
}
}
}
我也不知道我这样写购物车的模型思想好不好,如果哪位朋友能提供很好的思想。本人一定再加50分奉送(最好有源码贴出)。
类大概是这样的,有一个Shoppings类(购物车组类)
在Shoppings类里再写一个Shopping类(购物车类)
在写Shoppings类的索引访问器类时出现了问题,问题如下:
可访问性不一致: 索引器返回类型“shoppingApplication.Shoppings.Shopping”比索引器“shoppingApplication.Shoppings.this[int]”的访问性低源码如下:
using System;namespace shoppingApplication
{
public class Shoppings
{
class Shopping
{
public static int shoppingCount=0;
private string shoppingName;
private int shoppingId;
private string articleName;
private double articlePrice;
Shopping()
{
this.shoppingName="";
this.shoppingid=Shopping.shoppingCount++;
this.articleName="";
this.articlePrice=0.0;
}
Shopping(string shoppingName)
{
this.shoppingName=shoppingName;
this.shoppingid=Shopping.shoppingCount++;
this.articleName="";
this.articlePrice=0.0;
}
Shopping(string shoppingName,string articleName,double articlePrice)
{
this.shoppingName=shoppingName;
this.shoppingid=Shopping.shoppingCount++;
this.articleName=articleName;
this.articlePrice=articlePrice;
}
public string ShoppingName
{
set
{
this.shoppingName=value;
}
get
{
return this.shoppingName;
}
}
public int ShoppingID
{
set
{
this.shoppingId=value;
}
get
{
return this.shoppingId;
}
}
public string ArticleName
{
set
{
this.articleName=value;
}
get
{
return this.articleName;
}
}
public double ArticlePrice
{
set
{
this.articlePrice=value;
}
get
{
return this.articlePrice;
}
}
} private Shopping[] listShoppings;
public Shoppings()
{
this.listShoppings=new Array[10];
}
public Shoppings(int index)
{
this.listShoppings=new Array[index];
}
public Shopping this [int index]
{
set
{
if(index>=0 || index<Shopping.shoppingCount)
this.listShoppings[index]=value;
}
get
{
if(index>=0 || index<Shopping.shoppingCount)
return this.listShoppings[index];
else
return new Shopping();
}
}
}
}
我也不知道我这样写购物车的模型思想好不好,如果哪位朋友能提供很好的思想。本人一定再加50分奉送(最好有源码贴出)。
解决方案 »
- 是这样的 %L'N')'P?
- 关于水晶报表问题
- vs05向导生成的DataSet如何使用参数???
- 如何把DataTable的内容放入string【】【】中
- 求一个C#正则表达式,谢谢!
- .net可以编写上位机程序吗?
- 关于Load事件的调用问题,请大侠帮忙。
- 如何根据容量按不同的类别统计??
- 急,C#中如何加入一个做好的帮助文件?
- HtmlAgilityPack HtmlNode的SelectNodes有点神奇
- DataTable已经存在如何在里面增加2列
- 数据库连接异常:System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.
{
public class Shoppings
{
class Shopping
{
public static int shoppingCount=0;
private string shoppingName;
private int shoppingId;
private string articleName;
private double articlePrice;
public Shopping()
{
this.shoppingName="";
this.shoppingId=Shopping.shoppingCount++;
this.articleName="";
this.articlePrice=0.0;
}
Shopping(string shoppingName)
{
this.shoppingName=shoppingName;
this.shoppingId=Shopping.shoppingCount++;
this.articleName="";
this.articlePrice=0.0;
}
Shopping(string shoppingName,string articleName,double articlePrice)
{
this.shoppingName=shoppingName;
this.shoppingId=Shopping.shoppingCount++;
this.articleName=articleName;
this.articlePrice=articlePrice;
}
public string ShoppingName
{
set
{
this.shoppingName=value;
}
get
{
return this.shoppingName;
}
}
public int ShoppingID
{
set
{
this.shoppingId=value;
}
get
{
return this.shoppingId;
}
}
public string ArticleName
{
set
{
this.articleName=value;
}
get
{
return this.articleName;
}
}
public double ArticlePrice
{
set
{
this.articlePrice=value;
}
get
{
return this.articlePrice;
}
}
} private Shopping[] listShoppings;
public Shoppings()
{
this.listShoppings=new Shopping[10];
}
public Shoppings(int index)
{
this.listShoppings=new Shopping[index];
}
private Shopping this [int index]
{
set
{
if(index>=0 || index<Shopping.shoppingCount)
this.listShoppings[index]=value;
}
get
{
if(index>=0 || index<Shopping.shoppingCount)
return this.listShoppings[index];
else
return new Shopping();
}
} }
}
外部是无法访问的,所以索引无法返回一个Shopping类型的对象
我觉得应该把shopping类写在外面,如果你在外部要直接使用这个类的话
不过本人也在学习中
希望和大家一块学习学习
我看了C#的书好像没有看到动态分配内存的知识,不过可以动态的改变数组的大小来实现数组已满还能添加数据。不过这样的话是不是比较慢了。