如何访问其他类中的一个类的属性? [英] How to access property of one class in other class?
本文介绍了如何访问其他类中的一个类的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个类
如下
public class clsCustomer
{
private string strcustomername = 跨度>;
private string strcustomercode = ;
private string strcity = ;
public string 客户名
{
set
{
strcustomername = value ;
}
get
{
return strcustomername;
}
}
public string CustomerCode
{
set
{
strcustomercode = 值跨度>;
}
get
{
return strcustomercode;
}
}
public string 城市
{
set
{
strcity = value ;
}
获取
{
返回 strcity;
}
}
public clsOrder [] Orders = null < /跨度>;
}
class clsOrder
{
private < span class =code-keyword> string strProductname;
public string ProductName
{
set
{
strProductname = value ;
}
get
{
return strProductname;
}
}
}
class clsLINQ
{
clsCustomer [] objcustomer = < span class =code-keyword> new clsCustomer []
{
new clsCustomer(CustomerName = Khadak,CustomerCode = 001,City = Ludhiana,
订单= new clsOrder []
( new clsOrder(ProductName = 衬衫),
new clsOrder(ProductName = < span class =code-string> 袜子))),
new clsCustomer(CustomerName = DEV,CustomerCode = 002,City = Ludhiana,
订单= new clsOrder []
( new clsOrder(ProductName = 衬衫))),
new clsCustomer(CustomerName = AWE,CustomerCode = 003,City = Ludhiana,
Orders = new clsOrder []
( new clsOrder(ProductName = 袜子s)))
}};
但是收到错误
clsLINQ 错误是客户名在当前上下文中不存在。同样适用于客户代码和城市和订单
请告诉问候
解决方案
访问这里.... < br $> b $ b
http://stackoverflow.com/questions/1707004/how-to-use-aa-string-of-one-class-in-another-class [ ^ ]
或
< br $> b $ b
http://stackoverflow.com/questions/6986939/how-to-access-variable-from-one-class-in-another-class-c [ ^ ]
I have created one class
as below
public class clsCustomer
{
private string strcustomername = "";
private string strcustomercode = "";
private string strcity = "";
public string CustomerName
{
set
{
strcustomername=value;
}
get
{
return strcustomername;
}
}
public string CustomerCode
{
set
{
strcustomercode=value;
}
get
{
return strcustomercode;
}
}
public string City
{
set
{
strcity=value;
}
get
{
return strcity;
}
}
public clsOrder[] Orders = null;
}
class clsOrder
{
private string strProductname;
public string ProductName
{
set
{
strProductname=value;
}
get
{
return strProductname;
}
}
}
class clsLINQ
{
clsCustomer[] objcustomer=new clsCustomer[]
{
new clsCustomer(CustomerName="Khadak",CustomerCode="001",City="Ludhiana",
Orders=new clsOrder[]
(new clsOrder(ProductName="Shirt"),
new clsOrder(ProductName="Socks"))),
new clsCustomer(CustomerName="DEV",CustomerCode="002",City="Ludhiana",
Orders=new clsOrder[]
(new clsOrder(ProductName="Shirt"))),
new clsCustomer(CustomerName="AWE",CustomerCode="003",City="Ludhiana",
Orders=new clsOrder[]
(new clsOrder(ProductName="Socks")))
}};
but getting an error
in clsLINQ error is "CustomerName doesnot exist in current context". same for customercode and city and Orders
pls tell regards
解决方案
visit here....
http://stackoverflow.com/questions/1707004/how-to-use-a-a-string-of-one-class-in-another-class[^]
or
http://stackoverflow.com/questions/6986939/how-to-access-variable-from-one-class-in-another-class-c[^]
这篇关于如何访问其他类中的一个类的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文