我在 .NET 中使用 void 函数时遇到问题 fiddle
I'm having trouble using void functions in .NET fiddle
我目前正在参加 It1050 class,我是编码新手。我在他们的程序中使用 void 函数时遇到问题。我想知道是否有人可以帮助我解决问题。该网站有问题,无论我做什么,我都无法使代码正常工作。即使在我的导师给了我一些关于该做什么的指导之后。我有一个 link 您可以更改的代码。任何帮助将不胜感激!
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 */ }
}
调用其他方法中的方法
Local functions (C# Programming Guide) 并且从 C# 7.0 开始可用。
当您 select .NET 4.7.2 编译器时,.NET fiddle 显然不支持 C# 7.0。 Select .NET 5 或 Roslyn 3.8 编译器,或者将函数从 Main
方法中移出到 class 级别并使其成为静态的(因为您是从 Main
这也是静态的)。
我目前正在参加 It1050 class,我是编码新手。我在他们的程序中使用 void 函数时遇到问题。我想知道是否有人可以帮助我解决问题。该网站有问题,无论我做什么,我都无法使代码正常工作。即使在我的导师给了我一些关于该做什么的指导之后。我有一个 link 您可以更改的代码。任何帮助将不胜感激!
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 */ }
}
调用其他方法中的方法 Local functions (C# Programming Guide) 并且从 C# 7.0 开始可用。
当您 select .NET 4.7.2 编译器时,.NET fiddle 显然不支持 C# 7.0。 Select .NET 5 或 Roslyn 3.8 编译器,或者将函数从 Main
方法中移出到 class 级别并使其成为静态的(因为您是从 Main
这也是静态的)。