Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对象、继承和列表属性不´;行不通_C#_Inheritance - Fatal编程技术网

C# 对象、继承和列表属性不´;行不通

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 {

我是新来的。。。到目前为止,我一直使用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 { 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);
也可以吗?