sammarcow
sammarcow

Reputation: 2956

asp.net Syntax [] instead of ()

Can some one explain why brackets are used instead of () in the single line of code below (c# codeBehind ASP.NET), and provide the technical document reference for this syntax

string cssFile = Request.Cookies["InquiryId"].Value;

Upvotes: 0

Views: 269

Answers (4)

Achim
Achim

Reputation: 15722

Because Cookies is some kind of dictionary. Or more general: It defines an indexer property. Therefor the [] have to be used. () are used for a method call, which is just something different.

Upvotes: 1

Pharabus
Pharabus

Reputation: 6062

its a c# rather than VB.Net convention for accessing an array, nothing to do with asp.net really, rather the language choice for the code behind

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1039110

You may take a look at indexed properties. That's what is defined for the Cookies property.

Upvotes: 4

Bala R
Bala R

Reputation: 108967

the [] syntax that you are looking at is called the Indexers(msdn link).

Upvotes: 3

Related Questions