By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Syntax question

P: n/a
I stumbled across an older post:

http://msdn.microsoft.com/newsgroups...xp=&sloc=en-us

Which uses the ! in a way I haven't seen before and I'm having trouble
figuring out what it's doing there. The line is:

=CDate(Parameters!StartDate.Value).AddMonths(-1).ToString("MMMM")

The only thing I've found on ! is that it indicates:
"Appending the identifier type character ! to any identifier forces it to
Single." (From .NET 1.1 Framework docs) but that is for vb.net and not c#, so
I don't think it would apply.

Anyone have any insight on this?

-Ben
Dec 30 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Ben R." <be**@newsgroup.nospam> schrieb:
I stumbled across an older post:

http://msdn.microsoft.com/newsgroups...xp=&sloc=en-us

Which uses the ! in a way I haven't seen before and I'm having trouble
figuring out what it's doing there. The line is:

=CDate(Parameters!StartDate.Value).AddMonths(-1).ToString("MMMM")

The only thing I've found on ! is that it indicates:
"Appending the identifier type character ! to any identifier forces it to
Single." (From .NET 1.1 Framework docs) but that is for vb.net and not c#,
so
I don't think it would apply.


'!' can be used with default properties to access a certain item.

\\\
Dim c As New Collection
c.Add("Bla", "Goo")

' Semantically equivalent lines.
MsgBox(c!Goo)
MsgBox(c("Goo"))
MsgBox(c.Item("Goo"))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 30 '05 #2

P: n/a
Very interesting. Is there any documentation out there on this? Must the
accessor be a string? You're using "goo" with quotes and then with the !,
it's not with quotes so I'm assuming this is implied. Does this mean you
couldn't use, say, an integer accessor?

"Herfried K. Wagner [MVP]" wrote:
"Ben R." <be**@newsgroup.nospam> schrieb:
I stumbled across an older post:

http://msdn.microsoft.com/newsgroups...xp=&sloc=en-us

Which uses the ! in a way I haven't seen before and I'm having trouble
figuring out what it's doing there. The line is:

=CDate(Parameters!StartDate.Value).AddMonths(-1).ToString("MMMM")

The only thing I've found on ! is that it indicates:
"Appending the identifier type character ! to any identifier forces it to
Single." (From .NET 1.1 Framework docs) but that is for vb.net and not c#,
so
I don't think it would apply.


'!' can be used with default properties to access a certain item.

\\\
Dim c As New Collection
c.Add("Bla", "Goo")

' Semantically equivalent lines.
MsgBox(c!Goo)
MsgBox(c("Goo"))
MsgBox(c.Item("Goo"))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 30 '05 #3

P: n/a
Ben,

"Ben R." <be**@newsgroup.nospam> schrieb:
Very interesting. Is there any documentation out there on this? Must the
accessor be a string? You're using "goo" with quotes and then with the !,
it's not with quotes so I'm assuming this is implied. Does this mean you
couldn't use, say, an integer accessor?


It will only work with classes which have a default property which accepts a
single string parameter:

Visual Basic Language Concepts -- Special Characters in Code
<URL:http://msdn2.microsoft.com/en-us/library/xxda45fy.aspx>
-> "Exclamation Point ('!') Operator"

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 30 '05 #4

P: n/a
You can find documentation here:
http://msdn2.microsoft.com/en-us/library/xxda45fy.aspx

According to this document, the class must have a default property that
accepts a String as an argument. So it won't work with integers.

I believe this is around from VB6, actually, and that is why it is in .NET.
It's a compatibility issue, instead of MS thinking this would be a nice
feature to have around.

"Ben R." <be**@newsgroup.nospam> wrote in message
news:F9**********************************@microsof t.com...
Very interesting. Is there any documentation out there on this? Must the
accessor be a string? You're using "goo" with quotes and then with the !,
it's not with quotes so I'm assuming this is implied. Does this mean you
couldn't use, say, an integer accessor?

"Herfried K. Wagner [MVP]" wrote:
"Ben R." <be**@newsgroup.nospam> schrieb:
>I stumbled across an older post:
>
> http://msdn.microsoft.com/newsgroups...xp=&sloc=en-us
>
> Which uses the ! in a way I haven't seen before and I'm having trouble
> figuring out what it's doing there. The line is:
>
> =CDate(Parameters!StartDate.Value).AddMonths(-1).ToString("MMMM")
>
> The only thing I've found on ! is that it indicates:
> "Appending the identifier type character ! to any identifier forces it
> to
> Single." (From .NET 1.1 Framework docs) but that is for vb.net and not
> c#,
> so
> I don't think it would apply.


'!' can be used with default properties to access a certain item.

\\\
Dim c As New Collection
c.Add("Bla", "Goo")

' Semantically equivalent lines.
MsgBox(c!Goo)
MsgBox(c("Goo"))
MsgBox(c.Item("Goo"))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 30 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.