Similar to Finding the variable name passed to a function
The main difference is that I'm using a variable passed by reference, and in particular, I don't actually have an object instance at the time that I'm calling the nameof
function
For example:
class blank
{
}
class Program
{
static blank yes;
static void test<T>(ref T no)
{
Console.WriteLine(nameof(no)); //outputs no
}
static void Main(string[] args)
{
test(ref yes);
}
}
Is there a way to get "yes" printed instead of "no"? It feels like because I'm passing it by reference, there should be a way I can get at the actual name somehow.
Aucun commentaire:
Enregistrer un commentaire