• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 34
  • Last Modified:

Question about logical operand.

I am looking at some VB.net code and see this line of code ==>   var type = fInfo?.FieldType ?? pInfo.pType;

I know this is a logical comparison statement, but what does the first question mark mean (finfo?.FieldType)

Can a VB.net expert help me figure that out?
0
brgdotnet
Asked:
brgdotnet
  • 2
  • 2
3 Solutions
 
Éric MoreauSenior .Net ConsultantCommented:
This is called the Elvis operator. If ever fInfo is null, your application won't trigger an error. It will simply fill type with null. Otherwise (if fInfo is not null), type will be filled with FieldType.
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>I am looking at some VB.net code and see this line of code ==>   var type = fInfo?.FieldType ?? pInfo.pType;

and BTW, this line is in C#, not in VB.Net
0
 
Fernando SotoRetiredCommented:
Hi brgdotnet;

It is called the null-conditional Operators. Used to test for null before performing a member access (?.) or index (?[]) operation. These operators help you write less code to handle null checks, especially for descending into data structures.
0
 
brgdotnetcontractorAuthor Commented:
Both answers were high quality. Thanks.
0
 
Fernando SotoRetiredCommented:
Not a problem brgdotnet, glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now