using nameof to check the name

Jassim Al Rahma 1,526 Reputation points
2022-05-14T20:54:59.433+00:00

Hi,

How can I check the nameof to check the name like this:

if (nameof(stackLayout) == "StackLayoutCurrentUV")
{
    uv = true;
}
else
{
    uv = false;
}

I tried the above but did not work

Kind Regards,
Jassim Al Rahma

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,307 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,931 Reputation points
    2022-05-14T21:22:35.39+00:00

    nameof() is a compile time feature, and returns the name of the variable.

    nameof(stackLayout) == “stackLayout”