Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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# CSharpCodeProvider没有看到堆栈<;T>;在System.Collections.Generic下初始化_C#_.net_Compiler Errors_Pseudocode_Csharpcodeprovider - Fatal编程技术网

C# CSharpCodeProvider没有看到堆栈<;T>;在System.Collections.Generic下初始化

C# CSharpCodeProvider没有看到堆栈<;T>;在System.Collections.Generic下初始化,c#,.net,compiler-errors,pseudocode,csharpcodeprovider,C#,.net,Compiler Errors,Pseudocode,Csharpcodeprovider,我正在构建一个伪代码转换器和编译器。 它通过执行几个字符串操作将伪代码转换为代码,然后使用类编译伪代码,最后尝试运行伪代码 经过几次测试后,在翻译/输出代码如下的情况下: using System; using System.Collections.Generic; public class TranslatedProgram { public static void ReadLine(ref int destiny) { destiny = int.Parse

我正在构建一个伪代码转换器和编译器。 它通过执行几个字符串操作将伪代码转换为代码,然后使用类编译伪代码,最后尝试运行伪代码

经过几次测试后,在翻译/输出代码如下的情况下:

using System;
using System.Collections.Generic;

public class TranslatedProgram
{
    public static void ReadLine(ref int destiny)
    {
        destiny = int.Parse(Console.ReadLine());
    }
    public static void InsertInStack(ref Stack<int> originalStack, int value)
    {
        Console.WriteLine("Inserting the value " + value + " to the stack.");
        originalStack.Push(value);
        foreach (int current in originalStack)
        {
            Console.WriteLine("|" + current);
        }
        Console.WriteLine("_______");
    }
    public static void Main()
    {
        int value = new int();
        Stack<int> data = new Stack<int>();
        ReadLine(ref value);
        InsertInStack(ref data, value);
    }
}

如何包含对System.dll的引用?

请确保在编译时,有一个对包含
堆栈的dll的引用,即
System.dll

您可以使用
CompilerParameters
类的属性
referencedAssemblys
添加引用:

CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerResults cr = provider.CompileAssemblyFromFile(cp, "MyFile.cs");

确保在编译时,有一个对保存
堆栈的dll的引用,即
System.dll

您可以使用
CompilerParameters
类的属性
referencedAssemblys
添加引用:

CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerResults cr = provider.CompileAssemblyFromFile(cp, "MyFile.cs");

使用CSharpCodeProvider编译时,是否将
System.dll
作为程序集引用?使用CSharpCodeProvider编译时,是否将
System.dll
作为程序集引用?我可以使用哪个属性向编译器提供该信息?这是我第一次使用这个类,我找不到任何属性或参数来执行此操作。我在答案中添加了更多信息。我可以使用哪个属性向编译器提供这些信息?这是我第一次使用这个类,我找不到任何属性或参数来执行此操作,我在答案中添加了更多信息。