В настоящее время я пытаюсь отобразить много каналов, и поэтому для удобства создал класс, который может содержать свойства канала и словарь, который отображает идентификатор на канал. Диктофон находится в одном классе, а определение канала - в своих собственных классах, но в одном и том же пространстве имен.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ParentId = System.String;
using ChildIds = System.Collections.Generic.List<int>;
using ChannelName = System.String;
using CatalogEntry = System.Tuple<System.String, System.Collections.Generic.List<int>, System.String>;
namespace example
{
public class ChannelHandler
{
public ChannelName channelname { get; set; }
public ParentId parentid { get; set; }
public ChildIds list_of_childs { get; set; }
public int id;
ChannelHandler(ChannelName name, int id)
{
this.channelname = name;
this.id = id;
}
ChannelHandler(ChannelName name, int id, ParentId parentid)
{
this.channelname = name;
this.id = id;
this.parentid = parentid;
}
}
public class Class1
{
private Dictionary<int?, ChannelHandler> dictionary = new Dictionary<int?, ChannelHandler>();
public void inser_into_dictionary(string path)
{
string[] separatingChars = { " " };
string[] splittedPath = path.Split(separatingChars, StringSplitOptions.RemoveEmptyEntries);
int parentId = 0;
ChannelName parentName = string.Empty;
foreach (string channel_id in splittedPath)
{
ChannelName name = channel_id.Split('_').ElementAt(0);
string id = channel_id.Split('_').ElementAt(1);
int int_id = 0;
if (int.TryParse(id, out int_id))
{
int_id = int.Parse(id);
}
Tuple<string, int> pair_of_channel_and_id = new Tuple<string, int>(name, int_id);
if (this.dictionary.ContainsKey(int_id))
{
// Key exist, meaning this is a parent.
// Child entry has to be updated.
parentId = int_id;
parentName = name;
}
else
{
if (parentId == 0)
{
ChannelHandler channel = new ChannelHandler(name, int_id); //ChannelHandler.ChannelHandler is inaccesible due to protection level.
this.dictionary.Add(int_id, channel);
}
}
}
}
}
}
Кажется, я не могу создать объект channel
, так как конструктор для класса кажется недоступным из-за уровня защиты? а какой уровень защиты - все публично?