小编Tir*_*ing的帖子

c#用于存储来自csv文件的值的适当数据结构.具体案例

我正在编写一个程序,它只会读取包含以下信息的2个不同的.csv文件:

file 1                  file2
AA,2.34                BA,6.45
AB,1.46                BB,5.45
AC,9.69                BC,6.21
AD,3.6                 AC,7.56
Run Code Online (Sandbox Code Playgroud)

第一列是string第二列,第二列是double.

到目前为止,我没有困难阅读这些文件并将值放入List:

firstFile = new List<KeyValuePair<string, double>>();
secondFile = new List<KeyValuePair<string, double>>();
Run Code Online (Sandbox Code Playgroud)

我正在尝试指导我的程序:

  • 从第一个文件的第一行的第一列获取第一个值(在这种情况下AA)
  • 并查看第二个文件中的整个第一列中是否存在匹配项.
  • 如果找到字符串匹配,则比较它们对应的第二个值(double在这种情况下),如果在这种情况下匹配,则将整行添加到单独的行中List.

类似于下面的伪代码:

for(var i=0;i<firstFile.Count;i++)
{
    firstFile.Column[0].value[i].SearchMatchesInAnotherFile(secondFile.Column[0].values.All);
    if(MatchFound)
    {
        CompareCorrespondingDoubles();
        if(true)
        {
            AddFirstValueToList();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

而不是List我尝试使用,Dictionary但这个数据结构没有排序,也无法通过索引访问密钥.

不是要求提供确切的代码,而是问题是:

你建议将什么作为该程序的适当数据结构使用,以便我可以进一步调查自己?

c# csv data-structures

7
推荐指数
1
解决办法
456
查看次数

Git推送到远程存储库上的特定文件夹

如何推送到远程存储库中的特定文件夹?我的本地 C 驱动器上有以下结构:

myfolder/
    .git
    folder1
    folder2
    folder3
    folder4
    .gitignore
Run Code Online (Sandbox Code Playgroud)

git init在这个文件夹中执行了命令。之后我做了git add .然后git commit -m "My first commit"现在我想将它推送到包含类似结构的 VSTS远程存储库:

https://helloworld.visualstudio.com/VSTS_folder/_git/VSTS_folder

VSTS_folder/
   greenFolder
   redFolder
   blueFolder
   blackFolder
   yellowFolder
   .gitignore
   README.md
Run Code Online (Sandbox Code Playgroud)

其中VSTS_folder是存储库的名称。greenFolderredFolderyellowFolder已经有一些代码了。我想要做的是将我的本地内容推送到空的blackFolder远程文件夹。我试图避免弄乱 repo 并将我的东西推到根目录。我正在使用,git remote add origin https://helloworld.visualstudio.com/VSTS_folder/_git/VSTS_folder/blackFolder但没有用。实现此目的的适当 git 命令是什么?谢谢。

git directory push azure-devops

5
推荐指数
2
解决办法
2万
查看次数

在C#中处理交换机案例的更好方法

如果我的问题看起来很愚蠢,我会提前道歉,但由于某种原因,我无法通过更优雅的解决方案来解决问题.所以我有一个利用switch-case块的方法,类似于下面的代码块:

public enum Items
{
    item_1, item_2, item_3, .... item_N
};

private string String_1 {get; set;}
private string String_2 {get; set;}
private string String_3 {get; set;}
// ...
private string String_N {get; set;}

public void DoSomething(Items item){
    switch(item){
        case item_1:
            MethodNumberOne();
            MethodNumberTwo();
            MethodNumberThree();
            Console.WriteLine($"{0} is displayed on the page", String_1);
            break;

        case item_2:
            MethodNumberOne();
            MethodNumberTwo();
            MethodNumberThree();
            Console.WriteLine($"{0} is displayed on the page", String_2);
            break;

        case item_3:
            MethodNumberOne();
            MethodNumberTwo();
            MethodNumberThree();
            Console.WriteLine($"{0} is displayed on the page", String_3);
            break;
        // ...
        case …
Run Code Online (Sandbox Code Playgroud)

c# enums coding-style

3
推荐指数
1
解决办法
1012
查看次数

PowerShell:将数组转换为 html 表

如何将 PowerShell 中的简单哈希数组转换为 HTML 表?

$array = @{

"Name" = "My Name"
"Surname" = "My Surname"
"Address" = "My Address"
"DateOfBirth" = "My Date Of Birth"
"Hobby" = "My Hobby"
 "Age" = "My Age" 
 }
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

然后继续添加行?有没有人以前实现过这个?下面我将根据几个在线论坛提供我迄今为止尝试过的示例:

[System.Management.Automation.PSCustomObject]$array | ConvertTo-Html
-Fragment
Run Code Online (Sandbox Code Playgroud)

无法将“System.Collections.Hashtable”类型的“System.Collections.Hashtable”值转换为“System.Management.Automation.PSCustomObject”类型。在 line:0 char:0 + [System.Management.Automation.PSCustomObject]$array | ConvertTo-Html ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [], RuntimeException +fullyQualifiedErrorId : ConvertToFinalInvalidCastException

New-Object psobject -Property $array | ConvertTo-Html -Fragment
Run Code Online (Sandbox Code Playgroud)

System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry

$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | …
Run Code Online (Sandbox Code Playgroud)

html powershell converters

1
推荐指数
1
解决办法
5966
查看次数