Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the "!" symbol after ViewDataDictionary instance in VB.NET?

I created a new Web Application using Visual Studio 2015 RTM and choose MVC template for it.

it created me a bunch of code there including a controller named AccountController containing a method exactly like this:

<AllowAnonymous>
Public Function Login(returnUrl As String) As ActionResult
    ViewData!ReturnUrl = returnUrl
    Return View()
End Function

What the ! symbol does there? is it a part of vb.net syntax?

like image 377
Hamed Zakery Miab Avatar asked Sep 03 '15 19:09

Hamed Zakery Miab


1 Answers

It's the exclamation point operator. See section "Exclamation Point (!) Operator" in Special Characters in Code (Visual Basic):

Use the ! operator only on a class or interface as a dictionary access operator. The class or interface must have a default property that accepts a single String argument. The identifier immediately following the ! operator becomes the argument value passed to the default property as a string.

So, instead of doing:

ViewData("ReturnUrl") = returnUrl

You can do:

ViewData!ReturnUrl = returnUrl
like image 108
trashr0x Avatar answered Nov 10 '22 08:11

trashr0x