C# 对象、继承和列表属性不´;行不通
我是新来的。。。到目前为止,我一直使用VB6。 我有一门课:C# 对象、继承和列表属性不´;行不通,c#,inheritance,C#,Inheritance,我是新来的。。。到目前为止,我一直使用VB6。 我有一门课: public class clocation_base { public clocation_base() { } public string ID { get; set; } public string Name { get; set; } public Int32 ImagesCurrent { get; set; } public Int32 ImagesTotal {
public class clocation_base
{
public clocation_base()
{
}
public string ID { get; set; }
public string Name { get; set; }
public Int32 ImagesCurrent { get; set; }
public Int32 ImagesTotal { get; set; }
public DateTime? ImagesLastUpload { get; set; }
public decimal Lon { get; set; }
public decimal Lat { get; set; }
public int DistanceInMeter { get; set; }
public int Proofed { get; set; }
public DateTime Created { get; set; }
public string PreviewImg1 { get; set; }
public string PreviewImg2 { get; set; }
public string PreviewImg3 { get; set; }
public string PreviewImg4 { get; set; }
}
现在我想用一个列表(另一个类)来“扩展”这个类。
这是我的“清单:
现在,我将通过媒体列表“扩展”我的clocation_基础:
public class clocation_extended : clocation_base
{
List<clocation_media> media { get; set; }
public clocation_extended()
{
media = new List<clocation_media>();
}
}
现在我想使用:
mTest.media.Add("http://contoso.com/img1.jpg", "Image", null);
但这不起作用
mTest.media…
有人能帮我吗?类成员在C#中默认是私有的,因此您必须将
媒体
公开
public class clocation_extended : clocation_base
{
public List<clocation_media> media { get; set; }
public clocation_extended()
{
media = new List<clocation_media>();
}
}
将不起作用,因为媒体
的类型为列表
,因此您必须添加clocation\u媒体的实例
:
var media = new clocation_media
{
Type = "Image",
URL = "http://contoso.com/img1.jpg"
};
mTest.media.Add(media);
在C#中,默认情况下类成员是私有的,因此必须将
媒体
公开
public class clocation_extended : clocation_base
{
public List<clocation_media> media { get; set; }
public clocation_extended()
{
media = new List<clocation_media>();
}
}
将不起作用,因为媒体
的类型为列表
,因此您必须添加clocation\u媒体的实例
:
var media = new clocation_media
{
Type = "Image",
URL = "http://contoso.com/img1.jpg"
};
mTest.media.Add(media);
在C#中,默认情况下类成员是私有的,因此必须将
媒体
公开
public class clocation_extended : clocation_base
{
public List<clocation_media> media { get; set; }
public clocation_extended()
{
media = new List<clocation_media>();
}
}
将不起作用,因为媒体
的类型为列表
,因此您必须添加clocation\u媒体的实例
:
var media = new clocation_media
{
Type = "Image",
URL = "http://contoso.com/img1.jpg"
};
mTest.media.Add(media);
在C#中,默认情况下类成员是私有的,因此必须将
媒体
公开
public class clocation_extended : clocation_base
{
public List<clocation_media> media { get; set; }
public clocation_extended()
{
media = new List<clocation_media>();
}
}
将不起作用,因为媒体
的类型为列表
,因此您必须添加clocation\u媒体的实例
:
var media = new clocation_media
{
Type = "Image",
URL = "http://contoso.com/img1.jpg"
};
mTest.media.Add(media);
列表媒体{get;set;}
必须设置为public
,否则您无法从类外访问它。默认情况下,C#类中的成员是private
。如果您需要private列表媒体{get;set;}以外的内容,则必须指定访问器
必须设置为public
,否则您无法从类外访问它。默认情况下,C#类中的成员是private
。如果您需要private
以外的内容,则必须指定访问者
必须设置为public
,否则您无法从类外访问它。默认情况下,C#类中的成员是private
。如果您需要private
以外的内容,则必须指定访问者必须设置为public
,否则您无法从类外访问它。默认情况下,C#类中的成员是private
。如果您需要的不是private
的内容,则必须指定访问者,将列表媒体{get;set;}
更改为公共列表媒体{get;set;}
请使用。这将使其他人(可能包括您自己)更容易阅读您的代码。将列表媒体{get;set;}
更改为公共列表媒体{get;set;}
请使用。这将使其他人(可能包括您自己)更容易阅读您的代码。更改列表媒体{get;set;}
到公共列表媒体{get;set;}
请使用。这将使其他人(可能是您自己)更容易阅读您的代码。将列表媒体{get;set;}
更改为公共列表媒体{get;set;}
请使用。这将使其他人(可能是您自己)更容易阅读您的代码阅读你的代码。哇。简单。酷。你能提供一个片段吗,如何获取mTest.media.Add(“http://contoso.com/img1.jpg“,”Image“,null);
也能用吗?哇。简单。酷。你能提供一个片段,如何获取mTest.media.Add(”http://contoso.com/img1.jpg“,”图像“,空)
也可以吗?哇。简单。酷。你能提供一个片段,如何获取mTest.media.Add(“http://contoso.com/img1.jpg“,”Image“,null);
也能用吗?哇。简单。酷。你能提供一个片段,如何获取mTest.media.Add(”http://contoso.com/img1.jpg“,”Image“,null);
也可以吗?