Al

Al

  • 1.9k
  • 30
  • 2.7k

asp.net server control reference

Apr 25 2020 7:33 PM

Hi,

 I am familiar with this piece of code:

LinkButton myLb = (LinkButton)sender;
string cmd2 = myLb.CommandName;
 
However I came across this new code to me , but it does the same thing as the upper code. 

                string cmd = (sender as LinkButton).CommandName;

my question, is this a way of casting. How do I know when to use this kind of conversion.
 
Thanks
 
Al

Answers (2)