Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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# 当主题涉及到指针时,我失去了一半的学生。一个额外的间接层次,需要时间去理解。委托并不像指针那样不透明,所以现在不要惊慌。继续尝试使用它们,你会得到的!片刻没有人能真正为您加快速度。理解代表需要时间。回到过去,计算机科学101课程在涉及指针时会失去一半的学生_C#_Linq_Events_Methods_Delegates - Fatal编程技术网

C# 当主题涉及到指针时,我失去了一半的学生。一个额外的间接层次,需要时间去理解。委托并不像指针那样不透明,所以现在不要惊慌。继续尝试使用它们,你会得到的!片刻没有人能真正为您加快速度。理解代表需要时间。回到过去,计算机科学101课程在涉及指针时会失去一半的学生

C# 当主题涉及到指针时,我失去了一半的学生。一个额外的间接层次,需要时间去理解。委托并不像指针那样不透明,所以现在不要惊慌。继续尝试使用它们,你会得到的!片刻没有人能真正为您加快速度。理解代表需要时间。回到过去,计算机科学101课程在涉及指针时会失去一半的学生,c#,linq,events,methods,delegates,C#,Linq,Events,Methods,Delegates,当主题涉及到指针时,我失去了一半的学生。一个额外的间接层次,需要时间去理解。委托并不像指针那样不透明,所以现在不要惊慌。继续尝试使用它们,你会得到的!片刻没有人能真正为您加快速度。理解代表需要时间。回到过去,计算机科学101课程在涉及指针时会失去一半的学生。一个额外的间接层次,需要时间去理解。委托并不像指针那样不透明,所以现在不要惊慌。继续尝试使用它们,你会得到的!片刻没有人能帮你加快速度。第一段的解释太棒了!非常感谢您花时间向我解释这个概念!第一段的解释太棒了!非常感谢您花时间向我解释这个概念


当主题涉及到指针时,我失去了一半的学生。一个额外的间接层次,需要时间去理解。委托并不像指针那样不透明,所以现在不要惊慌。继续尝试使用它们,你会得到的!片刻没有人能真正为您加快速度。理解代表需要时间。回到过去,计算机科学101课程在涉及指针时会失去一半的学生。一个额外的间接层次,需要时间去理解。委托并不像指针那样不透明,所以现在不要惊慌。继续尝试使用它们,你会得到的!片刻没有人能帮你加快速度。第一段的解释太棒了!非常感谢您花时间向我解释这个概念!第一段的解释太棒了!非常感谢您花时间向我解释这个概念!
class Program
{
    // Define our delegate type: pointer to any method taking in string parameter and returning void
    public delegate void Write(string theText);

    // Method for output to screen
    public static void OutputToScreen(string theText)
    {
        Console.WriteLine(theText);
    }

    // Method to output to file
    public static void WriteToFile(string theText)
    {
        StreamWriter fileWriter = File.CreateText("delegatedemo.txt");
        fileWriter.WriteLine(theText);
        fileWriter.Flush();
        fileWriter.Close();
    }

    public static void Main()
    {
        // Assign a method to a delegate
        Write toFile = new Write(WriteToFile);
        Write toScreen = new Write(OutputToScreen);

        Display("This is a delegate demo", toFile);
        Display("This is a delegate demo", toScreen);
    }

    public static void Display(string theText, Write outputMethod)
    {
        outputMethod(theText);
    }
}
class Program
{
    // Method for output to screen
    public static void OutputToScreen(string theText)
    {
        Console.WriteLine(theText);
    }

    // Method to output to file
    public static void WriteToFile(string theText)
    {
        StreamWriter fileWriter = File.CreateText("theFile.txt");
        fileWriter.WriteLine(theText);
        fileWriter.Flush();
        fileWriter.Close();
    }

    public static void Main()
    {
        WriteToFile("This is not a delegate demo");
        OutputToScreen("This is not a delegate demo");
    }
}
class Program
{
    // Method to output to file
    public static void WriteToFile(string theText)
    {
        StreamWriter fileWriter = File.CreateText("theFile.txt");
        fileWriter.WriteLine(theText);
        fileWriter.Flush();
        fileWriter.Close();
    }

    public static void Main()
    {
        WriteToFile("This is not a delegate demo");
        Console.WriteLine("This is not a delegate demo");
    }
}
class Program
{

    // Method for output to screen
    public static void OutputToScreen(string theText)
    {
        Console.WriteLine(theText);
    }

    // Method to output to file
    public static void WriteToFile(string theText)
    {
        StreamWriter fileWriter = File.CreateText("delegatedemo.txt");
        fileWriter.WriteLine(theText);
        fileWriter.Flush();
        fileWriter.Close();
    }

    public static void Main()
    {
        Display("This is a delegate demo", 1);
        Display("This is a delegate demo", 2);
    }

    public static void Display(string theText, int type)
    {
        if( type == 1)
            WriteToFile(theText);
        else if( type == 1)
            OutputToScreen(theText);
    }
}
class Program {
    enum WriteType { ToScreen, ToFile };

    // Method for output to screen
    public static void OutputToScreen(string theText) {
        Console.WriteLine(theText);
    }

    // Method to output to file
    public static void WriteToFile(string theText) {
        StreamWriter fileWriter = File.CreateText("nondelegatedemo.txt");
        fileWriter.WriteLine(theText);
        fileWriter.Flush();
        fileWriter.Close();
    }

    public static void Main() {
        Display("This is a non-delegate demo", WriteType.ToFile);
        Display("This is a non-delegate demo", WriteType.ToScreen);
    }

    public static void Display(string theText, WriteType outputMethod) {
        switch (outputMethod) {
        case WriteType.ToFile: WriteToFile(theText); break;
        case WriteType.ToScreen: WriteToScreen(theText); break;
        }
    }
}
public static void Main()
{
    // Same runtime effect, but less flexibility: the effects are hardcoded
    WriteToFile("This is not a delegate demo");
    OutputToScreen("This is not a delegate demo");
}
public static void Main()
{
    DoSomethingWith("This is not a delegate demo", "display");
    DoSomethingWith("This is not a delegate demo", "write");
}

static void DoSomethingWith(string str, string what)
{
    // Same runtime effect and flexibility, but...
    switch (what) {
        case "display": 
            OutputToScreen(str); break;
        case "write:
            WriteToFile(str); break;
        // what happens if "what" is neither of the above?
    }
}
interface IWriter {
    public static void Write(string text);
}
class FileWriter : IWriter {
    public void Write(string text)
    {
        StreamWriter fileWriter = File.CreateText("delegatedemo.txt");
        fileWriter.WriteLine(theText);
        fileWriter.Flush();
        fileWriter.Close();
    }
}
class ConsoleWriter: IWriter {
    public void Write(string text)
    {
        Console.WriteLine(theText);
    }
}
public static void Main()
{
    new FileWriter.Write("This is a NOT delegate demo");
    new ConsoleWriter.Write("This is NOT a delegate demo");
}
public static void Display(string theText, Action<string> outputMethod)
{
    outputMethod(theText);
}
Display("Hello World", WriteToFile);
Display("Hello World", OutputToScreen);