Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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中通过采集存储和检索多维数据#_C#_Collections - Fatal编程技术网

C# 如何在c中通过采集存储和检索多维数据#

C# 如何在c中通过采集存储和检索多维数据#,c#,collections,C#,Collections,我需要像这样存储和访问数据 [0] - [0] "some value string7", "some value string 1"; [1] "some value string9", "some value string 2"; [1] - [0] "some value strin78", "some value string 34"; [1] "some value string12"

我需要像这样存储和访问数据

[0]   -   
          [0] "some value string7", "some value string 1";
          [1] "some value string9", "some value string 2";

[1]   -   
          [0] "some value strin78", "some value string 34";
          [1] "some value string12", "some value string 56";
          [2] "some value string78", "some value string 12";

[2]   -   [0] "some value string128", "some value string 4";

[3]   -   [0] "some value string65", "some value string 14";
          [1] "some value string85", "some value string 65";
          [2] "some value string95", "some value string 67";
          [3] "some value string13", "some value string 87"
基本上,我正在用windows窗体制作一个重命名程序,该程序有各种类型的重命名方案,其编号一直在变化。我想为许多步骤创建撤消操作。我使用拖放来获取文件名和位置。我使用两个列表完成了一个步骤。但我只能做一步。上面的场景应该出现在重命名的每个操作中,我不知道应该使用哪个变量

I'm using this code for one step 
 for (int i = 0; i < item_Name_New.Count; i++)
 {
     File.Move(item_Name_New[i], item_Name_Old[i]);
 }
我将此代码用于一个步骤
对于(int i=0;i
item_Name_New和item_Name_Old都是具有重命名方案上次操作的新旧名称的列表

选项1 创建用于存储新文件名和旧文件名的类,并使用嵌套列表:

public class FileAction
{
  public string Old { get; set; }
  public string New { get; set; }
}
用法:

// A step (item of list) consists of one to many rename actions
List<List<FileAction>> steps = new List<List<FileAction>>();

// ... fill list ...

// Handle steps
foreach (var step in steps)
{
  foreach (var action in step)
  {
    File.Move(action.Old, action.New);
  }
}
List<Step> steps = new List<Step>();

// ... fill list ...

// Handle steps
foreach (var step in steps)
{
  foreach (var action in step.Actions)
  {
    File.Move(action.Old, action.New);
  }
}
用法:

// A step (item of list) consists of one to many rename actions
List<List<FileAction>> steps = new List<List<FileAction>>();

// ... fill list ...

// Handle steps
foreach (var step in steps)
{
  foreach (var action in step)
  {
    File.Move(action.Old, action.New);
  }
}
List<Step> steps = new List<Step>();

// ... fill list ...

// Handle steps
foreach (var step in steps)
{
  foreach (var action in step.Actions)
  {
    File.Move(action.Old, action.New);
  }
}
列出步骤=新建列表();
// ... 填充列表。。。
//处理步骤
foreach(var步进)
{
foreach(步骤操作中的var操作)
{
File.Move(action.Old、action.New);
}
}
向列表中添加步骤:

// Get Actions
var actions = new List<FileAction>
{
  new FileAction { Old = "old-file.txt", New = "new-file.txt" },
  new FileAction { Old = "old-file.js", New = "new-file.js" }
};

// Add to steps
steps.Add(actions);
// Get Actions
var actions = new List<FileAction>
{
  new FileAction { Old = "old-file.txt", New = "new-file.txt" },
  new FileAction { Old = "old-file.js", New = "new-file.js" }
};

// Create and add step
var step = new Step { Actions = actions };
steps.Add(step);
//获取操作
var actions=新列表
{
新文件操作{Old=“Old file.txt”,new=“new file.txt”},
新建文件操作{Old=“Old file.js”,new=“new file.js”}
};
//创建并添加步骤
var步骤=新步骤{Actions=Actions};
步骤。添加(步骤);

您可以使用包含
字典
项的
列表
,其中键为新文件路径,值为旧文件路径:

var fileInfos = new List<Dictionary<string, string>>();

var newNameOldNamePairs1 = new Dictionary<string, string>() 
{ 
  { "C:\New Name 7.txt", "C:\Old Name 1.txt" },
  { "C:\New Name 9.txt", "C:\Old Name 2.txt" }
}

fileInfos.Add(newNameOldNamePairs1);

var newNameOldNamePairs2 = new Dictionary<string, string>();
newNameOldNamePairs2.Add("C:\New Name 78.txt", "C:\Old Name 34.txt");
newNameOldNamePairs2.Add("C:\New Name 12.txt", "C:\Old Name 56.txt");
newNameOldNamePairs2.Add("C:\New Name 78.txt", "C:\Old Name 12.txt");

fileInfos.Add(newNameOldNamePairs2);


// Iterate over the collection of key value pairs to rename the files
foreach (var entry in fileInfos.SelectMany(dictionary => dictionary))
{
  File.Move(entry.Key, entry.Value);           
}
var fileInfos=newlist();
var newNameOldNamePairs1=新字典()
{ 
{“C:\New Name 7.txt”,“C:\Old Name 1.txt”},
{“C:\New Name 9.txt”,“C:\Old Name 2.txt”}
}
fileInfos.Add(newNameOldNamePairs1);
var newNameOldNamePairs2=新字典();
newNameOldNamePairs2.Add(“C:\New Name 78.txt”,“C:\Old Name 34.txt”);
newNameOldNamePairs2.Add(“C:\New Name 12.txt”,“C:\Old Name 56.txt”);
newNameOldNamePairs2.Add(“C:\New Name 78.txt”,“C:\Old Name 12.txt”);
fileInfos.Add(newNameOldNamePairs2);
//迭代键值对集合以重命名文件
foreach(fileInfos.SelectMany中的var条目(dictionary=>dictionary))
{
File.Move(entry.Key,entry.Value);
}

非常感谢您。这帮助我提高了对收藏的理解。这对我很有帮助,我的代码已经到了最后一步。非常感谢。这对我很有帮助,我的代码到了步骤的末尾。现在我可以在不嵌入资源的情况下实现它了。再次感谢。