Click here to Skip to main content
14,422,161 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
OriginalGriff8-Dec-19 21:33
communityengineerOriginalGriff8-Dec-19 21:33 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
Super Lloyd9-Dec-19 0:30
MemberSuper Lloyd9-Dec-19 0:30 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
honey the codewitch9-Dec-19 0:32
mvahoney the codewitch9-Dec-19 0:32 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
OriginalGriff9-Dec-19 0:56
communityengineerOriginalGriff9-Dec-19 0:56 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
harold aptroot9-Dec-19 1:42
Memberharold aptroot9-Dec-19 1:42 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
honey the codewitch9-Dec-19 3:51
mvahoney the codewitch9-Dec-19 3:51 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
PIEBALDconsult9-Dec-19 9:26
professionalPIEBALDconsult9-Dec-19 9:26 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
OriginalGriff9-Dec-19 10:16
communityengineerOriginalGriff9-Dec-19 10:16 
I believe that was added at C# 7 - and it should work exactly as you show.

The
if (obj is string str)
   {
is really handy when you write event handlers, where you want to use a control:
private void AnEventHandler(object sender, EventArgs e)
   {
   if (sender is TextBox tb)
      {
      ...
      }
   }
Instead of
private void AnEventHandler(object sender, EventArgs e)
   {
   if (sender is TextBox)
      {
      TextBox tb = (TextBox) tb;
      ...
      }
   }
Or
private void AnEventHandler(object sender, EventArgs e)
   {
   TextBox tb = sender as TextBox;
   if (tb != null)
      {
      ...
      }
   }

"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!

GeneralRe: I never knew I'd miss an operator I hate so much Pin
PIEBALDconsult9-Dec-19 10:49
professionalPIEBALDconsult9-Dec-19 10:49 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
OriginalGriff9-Dec-19 22:14
communityengineerOriginalGriff9-Dec-19 22:14 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
PIEBALDconsult10-Dec-19 4:11
professionalPIEBALDconsult10-Dec-19 4:11 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
Super Lloyd9-Dec-19 0:29
MemberSuper Lloyd9-Dec-19 0:29 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
honey the codewitch9-Dec-19 0:30
mvahoney the codewitch9-Dec-19 0:30 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
Greg Utas9-Dec-19 2:11
professionalGreg Utas9-Dec-19 2:11 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
honey the codewitch9-Dec-19 3:54
mvahoney the codewitch9-Dec-19 3:54 
GeneralRe: I never knew I'd miss an operator I hate so much Pin
PIEBALDconsult9-Dec-19 9:10
professionalPIEBALDconsult9-Dec-19 9:10 
GeneralYAY! Slang parsed 8000+ lines of C# code. Pin
honey the codewitch8-Dec-19 17:29
mvahoney the codewitch8-Dec-19 17:29 
GeneralRe: YAY! Slang parsed 8000+ lines of C# code. Pin
Chris Maunder8-Dec-19 17:35
cofounderChris Maunder8-Dec-19 17:35 
GeneralRe: YAY! Slang parsed 8000+ lines of C# code. Pin
honey the codewitch8-Dec-19 18:08
mvahoney the codewitch8-Dec-19 18:08 
GeneralRe: YAY! Slang parsed 8000+ lines of C# code. Pin
PIEBALDconsult8-Dec-19 18:06
professionalPIEBALDconsult8-Dec-19 18:06 
GeneralRe: YAY! Slang parsed 8000+ lines of C# code. Pin
honey the codewitch8-Dec-19 18:07
mvahoney the codewitch8-Dec-19 18:07 
GeneralRe: YAY! Slang parsed 8000+ lines of C# code. Pin
PIEBALDconsult8-Dec-19 19:07
professionalPIEBALDconsult8-Dec-19 19:07 
GeneralRe: YAY! Slang parsed 8000+ lines of C# code. Pin
honey the codewitch8-Dec-19 19:10
mvahoney the codewitch8-Dec-19 19:10 
GeneralRe: YAY! Slang parsed 8000+ lines of C# code. Pin
PIEBALDconsult8-Dec-19 19:14
professionalPIEBALDconsult8-Dec-19 19:14 
GeneralRe: YAY! Slang parsed 8000+ lines of C# code. Pin
honey the codewitch8-Dec-19 19:16
mvahoney the codewitch8-Dec-19 19:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.