c# - 从 C# 向控制台应用程序传递参数

标签 c#

我需要从另一个 c# 应用程序运行控制台应用程序,如何从我的 c# 应用程序加载参数并将参数传递给控制台应用程序以执行控制台应用程序。 System.Diagnostics.ProcessStartInfo 有帮助吗?

最佳答案

使用 ProcessStartInfo 类

       ProcessStartInfo p = new ProcessStartInfo();
       p.Arguments = "your arguments";
       p.FileName = "Application or Document Name";
       Process.Start(p);





    public IList<string> GetMatchingWords(string word)
    {
        var list = new List<string>();

        int levelDepth = 0;
        if (string.IsNullOrEmpty(word))
            return list;

        var tempWord = word[0];
        var firstNode = RootNode.Childs.FirstOrDefault(x => x.Word[0].Equals(tempWord));

        if (firstNode == null)
        {
            return list;
        }


        var nodePath = new Queue<TrieNode>();

        var sb = new StringBuilder();
        sb.Append(firstNode.Word);



        while (firstNode != null)
        {


            levelDepth++;

            if (levelDepth == word.Length)
            {
                break;
            }



            tempWord = word[levelDepth];
              firstNode = firstNode.Childs.FirstOrDefault(x => x.Word[0].Equals(tempWord));

              sb.Append(firstNode.Word);

        }

        if(firstNode!=null)
            nodePath.Enqueue(firstNode);


        originalValue = sb.ToString();


        while (nodePath.Any())
        {
            var tempNode = nodePath.Dequeue();

            tempNode.IsParentNode = true;

            PopulateWords(tempNode, sb, ref list);

        }


        return list;
    }

    private void PopulateWords(TrieNode node,
         StringBuilder sb,ref List<string> list)
    {



        if (node.Childs.Any())
        {
            foreach (var temp in node.Childs)
            {
                if (node.IsParentNode)
                {
                    sb.Clear();
                    sb.Append(originalValue);
                }

                if (temp.Childs.Any())
                {

                    sb.Append(temp.Word);
                    PopulateWords(temp, sb, ref list);

                }
                else
                {
                    sb.Append(temp.Word);
                    list.Add(sb.ToString());
                }

            }
        }
        else
        {

            list.Add(sb.ToString());

        }


    }

关于c# - 从 C# 向控制台应用程序传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3985088/

相关文章:

c# - 为什么我无法捕捉到这个异常?

c# - 从 C# 转换后 Java 代码中的错误

c# - 将通用列表转换为特定类型

c# - 具有动态 Entity.Property 唯一检查的通用 ValidationAttribute(在运行时设置)

c# - 与 .NET 相比,OpenSSL HMACSHA256 产生不同的结果

c# - 如何决定使用 if/else 还是 try/catch?

c# - 使用预填充键定义字典 ​​c#

c# - FluentAssertions 应该在生产代码中使用吗?

c# - 如何从 CreateProcessWithLogonW 获取标准输出?

c# - GenericADOException 未处理无法插入