How does one acquire names of positional arguments? #111133
-
QueryAs The few relevant methods (as in, ways to accomplish this) present on the most popular online educational resources appear infeasibly difficult. As an example, although I expected VS Code's IntelliSense to provide this functionality, it does not appear to (on hover, anyway): Additionally, the code examples at If I've interpreted that Q&A correctly, am I forced to create a new project merely to ascertain what the names of a method's parameters are? If so, I'd rather not, so considering that PowerShell can call DotNet, perhaps there's a method via that which would be simpler? It would mean I wouldn't have to make a new project. I'd rather it were a feature in the IDE, though. RationaleI'm evaluating the Godot C# integration. My modified version of an official template 3 is undermentioned: using Godot;
using System;
public partial class Node3d : Godot.Node2D
{
private int FrameCount = 0;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
Godot.GD.Print("Start.");
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(System.Double delta)
{
FrameCount += 1;
Godot.GD.Print($"Frame {FrameCount}.");
}
} I want to know what the names for the parameters of Footnotes |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I think there are a few parts to your question:
I'll address each separately. How to know what parameter names should be when overriding a methodThe easiest way is to use an IDE. This is supported in Visual Studio and Visual Studio Code (with C# Dev Kit). Inside your class definition, type the keyword Do the names of parameters of an overriden method have to match the base classWhile it is the convention that parameters names of overriden methods match the parameter names defined in a base class, there is no requirement. For example, this code compiles: abstract class MyBaseClass
{
public abstract void Process(int x, string y);
}
class MySubClass : MyBaseClass
{
public override void Process(int a, string b)
{
Console.WriteLine($"MySubClass(a: {a}, b: {b})");
}
} Also note that using parameter names when calling a method is something that the compiler resolves at compile time using the type declariations available to it. It does not effect runtime. For example, this code: MySubClass sub = new MySubClass();
MyBaseClass downcasted = sub;
downcasted.Process(x: 1, y: "bob"); Will print the following when run:
However this code will not compile: MySubClass sub = new MySubClass();
sub.Process(x: 1, y: "bob"); Also note, you CANNOT reorder the parameters when overriding a method. This will not compile: class BadClass : MyBaseClass
{
public override void Process(string b, int a)
{
}
} How to know what argument names are when calling a methodYou can generally use IntelliSense in Visual Studio and Visual Studio Code to figure out parameter names. It will suggest parameter names for auto completion: If you are not using an IDE, you will instead have to rely on other sources for information about parameter names. You could consult the documentation. You could use a tool like IlSpy that lets you browse browse the list of classes and methods that are inside an assembly (the DLL file where a type is defined). Let me know if I failed to answer your question. |
Beta Was this translation helpful? Give feedback.
-
Your screenshot shows the parameter name. You seem to indicate that it does not though. What are you looking for that you don't seem to be getting? You can also get parameter names on the powershell prompt by leaving off the parenthesis of a function, at which point the overload information, including parameter names will be displayed.
|
Beta Was this translation helpful? Give feedback.
The parameter name is
delta
. When you call the method you can provide the named parameter instead of a positional one ie._Process(delta: 1234)
instead of_Process(1234)