动态3D阵列C#

时间:2014-01-03 10:19:53

标签: c# arrays dynamic 3d

您好我正在制作一个节目,其中一个方面是在某个时间和日期开放其他节目。

我想将细节添加到3D动态数组中,因为可能有许多程序需要添加。

    public static string[,,] programData = new string[,,]
    {
        //Program                   Monday          Tuesday     Wednesday       Thursday        Friday        Saturday      Sunday          Once
     {{"File Path","File Name"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"}},
     {{"File Path","File Name"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"}},
     {{"File Path","File Name"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"},{"Day","Time"}},

    };

数组应该有9行2列的固定值,但可能有很多程序[x,9,2]。

请留言这是不够的信息,谢谢。

2 个答案:

答案 0 :(得分:0)

您可以使用嵌套词典。

示例:

Dictionary<string, Dictionary<string, DateTime>> fileLaunchTimes = new Dictionary<string,       Dictionary<string, DateTime>>();
Dictionary<string, DateTime> dict = new Dictionary<string, DateTime>();
dict.Add("Monday", DateTime.Now); //etc (replace datetime.now with whatever time you want
dict.Add("Tuesday", DateTime.Now);
fileLaunchTimes.Add("filename", dict);

答案 1 :(得分:0)

我不知道锯齿状阵列的性能问题,但我认为你需要存储

程序的详细信息及其在程序中的相关可用时间。首先创建数据的模型对象,如

 public enum Days
    {
        Sunday = 0,
        Monday,
        Tuesday,
        WednessDay,
        Thursday,
        Friday,
        Saturday,
        Once
    }
    public class Day
    {

        public Days AssociateDay { get; set; } // used enum for better coding
        public DateTime Time { get; set; }
    }
public class Program
{
    public Program()
    {
        Days=new List<Day>();
    }
    public int Id { get; set; }
    public string FilePath { get; set; }
    public string FileName { get; set; }
    public List<Day> Days { get; private set; }

    public void AddDay(Day day)
    {
        if(Days.Any(x=>x.AssociateDay==day.AssociateDay))
        { // i dont know whats ur logic  here i am  returning without doing anything

            return;

        }

        Days.Add(day);

    }

}

public class MyProgram
{
    private static void Main(string[] args)
    {

        List<Program> Programs = new List<Program>();

        // Code to add new Program

        Program urProgram = new Program {FileName = "UrFile.aspx", FilePath = "Ur System Drive",Id = 1};
        urProgram.AddDay(new Day{AssociateDay = Days.Sunday,Time = DateTime.Now});

        Program myprogram = new Program { FileName = "MyFile.aspx", FilePath = "My System Drive" ,Id = 2};
        urProgram.AddDay(new Day { AssociateDay = Days.Monday, Time = DateTime.Now });



        Program theireePrgram = new Program { FileName = "theireeFile.aspx", FilePath = "their System Drive", Id = 3 };
        theireePrgram.AddDay(new Day { AssociateDay = Days.Monday, Time = DateTime.Now });

        // Your program object created now you can add to list collection

        Programs.Add(urProgram);
        Programs.Add(myprogram);
        Programs.Add(theireePrgram);

        // Update a program 

        int id = 1;

        var pgmUpdate = Programs.First(x => x.Id == 1);

        pgmUpdate.AddDay(new Day{AssociateDay = Days.Monday,Time = DateTime.Now});


        // Delete a program

        id = 3;
        Programs.Remove(Programs.First(x => x.Id == id));


        // List all programs


        foreach (var program in Programs)
        {
            Console.WriteLine(program.Id);
            Console.WriteLine(program.FileName);
            Console.WriteLine(program.FilePath);

            foreach (var day in program.Days)
            {
                Console.WriteLine(day.AssociateDay);
                Console.WriteLine(day.Time);
                Console.WriteLine("............................");
            }

            Console.WriteLine("*************************");
        }

        Console.ReadLine();



    }


}

这只是一个建议,因为这种编码给你很多感觉,在这里你可以轻松访问数据。处理数组有点棘手..