我在 .NET 小提琴中使用无效函数时遇到问题



我目前正在参加It1050课程,我是编码新手。我有一个问题与他们的程序使用void函数。我想知道是否有人能帮我解决这个问题。这个网站有点问题,无论我怎么做,我都无法使代码正常工作。甚至在我的教练给了我一些指导之后。我有一个你可以修改的代码链接。任何帮助将非常感激!

https://dotnetfiddle.net/fcen52

using System;

public class Program
{
public static void Main()
{
// Function - A code block that contains a series 
// of statements. A program causes the statements 
// To be exucuted by calling the function 
// and specifying anya required parameters.

// void function a function that does NOT have a
// return value.

// function type - the type of value the function 
// returns
// function name - The name you call the function 

// parameter - Information that is passed into functions 
// A parameter acts as a variable inside a function

greeting("Cole");
greeting("John");

void greeting(String name)
{ 

Console.WriteLine("Hello " + name); 
}  

// name is not valid. You cannot use name here. :(

}
//TEACHER'S COMMENT:
//Put your function outside of the main function scope
//Put "public static" before the return type.

//Example below:
//public static void greeting(String name) { /* Your code goes here */ }
}

方法内部的方法被调用本地函数(c#编程指南)和自c# 7.0起可用。

。当你选择。NET 4.7.2编译器时,NET fiddle显然不支持c# 7.0。选择。net 5或Roslyn 3.8编译器,或者选择将函数从Main方法移到类级别并使其静态(因为您从Main调用它也是静态的)。

最新更新