asp.net 不包含定义
自己写的类.namespaceOurShop.Models{publicclassShopCar{privateintgoodID;publicintGoodID{get...
自己写的类.
namespace OurShop.Models
{
public class ShopCar
{
private int goodID;
public int GoodID
{
get { return goodID; }
set { goodID = value; }
}
}
}
在网页.CS中using OurShop.Models了
ShopCar shopCar=new ShopCar();
shopCar.GoodID= 123;//此行报错,错误为ShopCar 不包含GoodID的定义!
求高手解答!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OurShop.Models
{
public class ShopCar
{
private int shopCarID;
public int ShopCarID
{
get { return shopCarID; }
set { shopCarID = value; }
}
private string userName;
public string UserName
{
get { return userName; }
set { userName = value; }
}
private int goodID;
public int GoodID
{
get { return goodID; }
set { goodID = value; }
}
private int quantity;
public int Quantity
{
get { return quantity; }
set { quantity = value; }
}
}
} 展开
namespace OurShop.Models
{
public class ShopCar
{
private int goodID;
public int GoodID
{
get { return goodID; }
set { goodID = value; }
}
}
}
在网页.CS中using OurShop.Models了
ShopCar shopCar=new ShopCar();
shopCar.GoodID= 123;//此行报错,错误为ShopCar 不包含GoodID的定义!
求高手解答!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OurShop.Models
{
public class ShopCar
{
private int shopCarID;
public int ShopCarID
{
get { return shopCarID; }
set { shopCarID = value; }
}
private string userName;
public string UserName
{
get { return userName; }
set { userName = value; }
}
private int goodID;
public int GoodID
{
get { return goodID; }
set { goodID = value; }
}
private int quantity;
public int Quantity
{
get { return quantity; }
set { quantity = value; }
}
}
} 展开
2个回答
展开全部
你贴的这段代码没有问题,在你页面中引用这个ShopCar类可能出现类重名!
比如你别的命名空间中也有银败叫锋枯颤做ShopCar这个类,那么你这么new这个ShopCar类就会出现败轿找不到GoodID定义,你把ShopCar shopCar = new ShopCar()改改
如下写:
OurShop.Models.ShopCar shopCar = new OurShop.Models.ShopCar();
比如你别的命名空间中也有银败叫锋枯颤做ShopCar这个类,那么你这么new这个ShopCar类就会出现败轿找不到GoodID定义,你把ShopCar shopCar = new ShopCar()改改
如下写:
OurShop.Models.ShopCar shopCar = new OurShop.Models.ShopCar();
追问
改了可以了,但是我检查了没有重名,为什么会这样呢?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询