question

JassimAlRahma-9056 avatar image
0 Votes"
JassimAlRahma-9056 asked JackJJun-MSFT commented

using nameof to check the name

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



dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@JassimAlRahma-9056, is any update? Do you still have problems about your question?

0 Votes 0 ·

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered AgaveJoe edited

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

nameof(stackLayout) == “stackLayout”

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tried this but did not work:

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


0 Votes 0 ·
AgaveJoe avatar image AgaveJoe JassimAlRahma-9056 ·

Clearly you are not paying attention to Bruce-SqlWorks's post or the nameof() reference documentation. Also you have not explained what "not work" means to you.

The nameof(stackLayout) method returns the variable name "stackLayout" and will never return "StackLayoutCurrentUV".

Should we assume to you want the variable's value???

 uv = stackLayout == "StackLayoutCurrentUV";





1 Vote 1 ·