Sideway
output.to from Sideway
Draft for Information Only

Content

VB.NET Miscellaneous Operators
  ?. and ?() null-conditional operators
  See also
  AddressOf Operator
  Syntax
  Parts
  Remarks
  See also
  Await Operator
  Exceptions
  See also
  GetType Operator
  Syntax
  Parameters
  Remarks
  See also
  Function Expression
  Syntax
  Parts
  Remarks
  Lambda Expression Syntax
  See also
  If Operator
  Syntax
  If Operator Called with Three Arguments
   Parts
  If Operator Called with Two Arguments
   Parts
  See also
  TypeOf Operator
  Syntax
  Parts
  Remarks
  See also
  Source/Reference

VB.NET Miscellaneous Operators

The supporting VB.NET Miscellaneous Operators are ?. (null-conditional), ?() (null-conditional), AddressOf, Await, GetType, Function (expression),  If, TypeOf.

?. and ?() null-conditional operators

Tests the value of the left-hand operand for null (Nothing) before performing a member access (?.) or index (?()) operation; returns Nothing if the left-hand operand evaluates to Nothing. Note that in expressions that ordinarily return value types, the null-conditional operator returns a Nullable<T>.

These operators help you write less code to handle null checks, especially when descending into data structures.

Sometimes you need to take an action on an object that may be null, based on the value of a Boolean member on that object. You can shorten your code and avoid manually checking for null by using the null-conditional operator.

The null-conditional operators are short-circuiting. If one operation in a chain of conditional member access and index operations returns Nothing, the rest of the chain’s execution stops.

Another use for null-conditional member access is to invoke delegates in a thread-safe way with much less code.

See also

AddressOf Operator

Creates a delegate instance that references the specific procedure.

Syntax

AddressOf procedurename  

Parts

procedurename: Required. Specifies the procedure to be referenced by the newly created delegate.

Remarks

The AddressOf operator creates a delegate that points to the sub or function specified by procedurename. When the specified procedure is an instance method then the delegate refers to both the instance and the method. Then, when the delegate is invoked the specified method of the specified instance is called.

The AddressOf operator can be used as the operand of a delegate constructor or it can be used in a context in which the type of the delegate can be determined by the compiler.

See also

Await Operator

You apply the Await operator to an operand in an asynchronous method or lambda expression to suspend execution of the method until the awaited task completes. The task represents ongoing work.

The method in which Await is used must have an Async modifier. Such a method, defined by using the Async modifier, and usually containing one or more Await expressions, is referred to as an async method.

Note

The Async and Await keywords were introduced in Visual Studio 2012. For an introduction to async programming, see Asynchronous Programming with Async and Await.

Typically, the task to which you apply the Await operator is the return value from a call to a method that implements the Task-Based Asynchronous Pattern, that is, a Task or a Task<TResult>.

Important

For the complete example, see Walkthrough: Accessing the Web by Using Async and Await. You can download the sample from Developer Code Samples on the Microsoft website. The example is in the AsyncWalkthrough_HttpClient project.

If Await is applied to the result of a method call that returns a Task(Of TResult), the type of the Await expression is TResult. If Await is applied to the result of a method call that returns a Task, the Await expression doesn't return a value.

An Await expression or statement does not block the thread on which it is executing. Instead, it causes the compiler to sign up the rest of the async method, after the Await expression, as a continuation on the awaited task. Control then returns to the caller of the async method. When the task completes, it invokes its continuation, and execution of the async method resumes where it left off.

An Await expression can occur only in the body of an immediately enclosing method or lambda expression that is marked by an Async modifier. The term Await serves as a keyword only in that context. Elsewhere, it is interpreted as an identifier. Within the async method or lambda expression, an Await expression cannot occur in a query expression, in the catch or finally block of a Try…Catch…Finally statement, in the loop control variable expression of a For or For Each loop, or in the body of a SyncLock statement.

Exceptions

Most async methods return a Task or Task<TResult>. The properties of the returned task carry information about its status and history, such as whether the task is complete, whether the async method caused an exception or was canceled, and what the final result is. The Await operator accesses those properties.

If you await a task-returning async method that causes an exception, the Await operator rethrows the exception.

If you await a task-returning async method that is canceled, the Await operator rethrows an OperationCanceledException.

A single task that is in a faulted state can reflect multiple exceptions. For example, the task might be the result of a call to Task.WhenAll. When you await such a task, the await operation rethrows only one of the exceptions. However, you can't predict which of the exceptions is rethrown.

For examples of error handling in async methods, see Try...Catch...Finally Statement.

See also

GetType Operator

Returns a Type object for the specified type. The Type object provides information about the type such as its properties, methods, and events.

Syntax

GetType(typename)  

Parameters

typename: The name of the type for which you desire information.

Remarks

The GetType operator returns the Type object for the specified typename. You can pass the name of any defined type in typename. This includes the following:

  • Any Visual Basic data type, such as Boolean or Date.

  • Any .NET Framework class, structure, module, or interface, such as System.ArgumentException or System.Double.

  • Any class, structure, module, or interface defined by your application.

  • Any array defined by your application.

  • Any delegate defined by your application.

  • Any enumeration defined by Visual Basic, the .NET Framework, or your application.

If you want to get the type object of an object variable, use the Type.GetType method.

The GetType operator can be useful in the following circumstances:

  • You must access the metadata for a type at run time. The Type object supplies metadata such as type members and deployment information. You need this, for example, to reflect over an assembly. For more information, see System.Reflection.

  • You want to compare two object references to see if they refer to instances of the same type. If they do, GetType returns references to the same Type object.

See also

Function Expression

Declares the parameters and code that define a function lambda expression.

Syntax

Function ( [ parameterlist ] ) expression  
- or -  
Function ( [ parameterlist ] )  
  [ statements ]  
End Function  

Parts

parameterlist: Optional. A list of local variable names that represent the parameters of this procedure. The parentheses must be present even when the list is empty. See Parameter List.

expression: Required. A single expression. The type of the expression is the return type of the function.

statements: Required. A list of statements that returns a value by using the Return statement. (See Return Statement.) The type of the value returned is the return type of the function.

Remarks

A lambda expression is a function without a name that calculates and returns a value. You can use a lambda expression anywhere you can use a delegate type, except as an argument to RemoveHandler. For more information about delegates, and the use of lambda expressions with delegates, see Delegate Statement and Relaxed Delegate Conversion.

Lambda Expression Syntax

The syntax of a lambda expression resembles that of a standard function. The differences are as follows:

  • A lambda expression does not have a name.

  • Lambda expressions cannot have modifiers, such as Overloads or Overrides.

  • Lambda expressions do not use an As clause to designate the return type of the function. Instead, the type is inferred from the value that the body of a single-line lambda expression evaluates to, or the return value of a multiline lambda expression. For example, if the body of a single-line lambda expression is Where cust.City = "London", its return type is Boolean.

  • The body of a single-line lambda expression must be an expression, not a statement. The body can consist of a call to a function procedure, but not a call to a sub procedure.

  • Either all parameters must have specified data types or all must be inferred.

  • Optional and Paramarray parameters are not permitted.

  • Generic parameters are not permitted.

See also

If Operator

Uses short-circuit evaluation to conditionally return one of two values. The If operator can be called with three arguments or with two arguments.

Syntax

If( [argument1,] argument2, argument3 )  

If Operator Called with Three Arguments

When If is called by using three arguments, the first argument must evaluate to a value that can be cast as a Boolean. That Boolean value will determine which of the other two arguments is evaluated and returned. The following list applies only when the If operator is called by using three arguments.

Parts

argument1: Required. Boolean. Determines which of the other arguments to evaluate and return.

argument2: Required. Object. Evaluated and returned if argument1 evaluates to True.

argument3: Required. Object. Evaluated and returned if argument1 evaluates to False or if argument1 is a NullableBoolean variable that evaluates to Nothing.

An If operator that is called with three arguments works like an IIf function except that it uses short-circuit evaluation. An IIf function always evaluates all three of its arguments, whereas an If operator that has three arguments evaluates only two of them. The first If argument is evaluated and the result is cast as a Boolean value, True or False. If the value is True, argument2 is evaluated and its value is returned, but argument3 is not evaluated. If the value of the Boolean expression is False, argument3 is evaluated and its value is returned, but argument2 is not evaluated.

If Operator Called with Two Arguments

The first argument to If can be omitted. This enables the operator to be called by using only two arguments. The following list applies only when the If operator is called with two arguments.

Parts

argument2: Required. Object. Must be a reference or nullable type. Evaluated and returned when it evaluates to anything other than Nothing.

argument3: Required. Object. Evaluated and returned if argument2 evaluates to Nothing.

When the Boolean argument is omitted, the first argument must be a reference or nullable type. If the first argument evaluates to Nothing, the value of the second argument is returned. In all other cases, the value of the first argument is returned.

See also

TypeOf Operator

Checks whether the runtime type of an expression's result is type-compatible with the specified type.

Syntax

result = TypeOf objectexpression Is typename  
result = TypeOf objectexpression IsNot typename  

Parts

result: Returned. A Boolean value.

objectexpression: Required. Any expression that evaluates to a reference type.

typename: Required. Any data type name.

Remarks

The TypeOf operator determines whether the run-time type of objectexpression is compatible with typename. The compatibility depends on the type category of typename. The following table shows how compatibility is determined.

Type category of typename Compatibility criterion
Class objectexpression is of type typename or inherits from typename
Structure objectexpression is of type typename
Interface objectexpression implements typename or inherits from a class that implements typename

If the run-time type of objectexpression satisfies the compatibility criterion, result is True. Otherwise, result is False. If objectexpression is null, then TypeOf...Is returns False, and ...IsNot returns True.

TypeOf is always used with the Is keyword to construct a TypeOf...Is expression, or with the IsNot keyword to construct a TypeOf...IsNot expression.

See also

Source/Reference


©sideway

ID: 200800006 Last Updated: 6/8/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 337

Reference 67

Computer

Hardware 149

Software

Application 198

Digitization 25

Latex 7

Manim 115

Numeric 19

Programming

Web 283

Unicode 494

HTML 65

CSS 58

ASP.NET 149

OS 389

DeskTop 7

Python 19

Knowledge

Mathematics

Formulas 8

Algebra 25

Number Theory 206

Trigonometry 18

Geometry 21

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Physics

Electric 27

Biology 1

Geography 1


Copyright © 2000-2020 Sideway . All rights reserved Disclaimers last modified on 06 September 2019