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

FxCop and String Creation Warning

P: n/a
I have just run FxCop and it reported a problem line 2 of the following:

<code>
Select Case e.Tool.Key.ToUpper
Case "FirstOption".ToUpper
' Do stuff

Case "SecondOption".ToUpper
' Do other stuff

Case Else
' Ignore anything else

End Select
</code>

It suggests that I should not create strings that are not subsequently
assigned to a variable, but to use String.Compare() instead.

Any thoughts on how one could do this and still use Select ... Case?

TIA

Charles
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Charles Law" <bl***@nowhere.com> schrieb:
I could write it as all uppercase, but I prefer to see it as mixed case as
I find it more readable. Also, the test then becomes dependent on the case
of the string. Ideally, there would be a way of making Select ... Case
perform a case insensitive test.


Take a look at 'Option Compare {Text, Binary}'.

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

Nov 21 '05 #2

P: n/a
What I mean is that it is dependent on me typing FirstOption in uppercase:
FIRSTOPTION.

Whereas

Case "FirstOption".ToUpper

is the same as

Case "FIRSTOPTION".ToUpper

i.e. it doesn't matter what case the string is in.

Charles
"Ray Cassick" <rc******@nospam.enterprocity.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
No... there sno need to make the text dependent on the case of the
stirng....

<code>
Select Case e.Tool.Key.ToUpper
Case "FIRSTOPTION"
' Do stuff

Case "SECONDOPTION"
' Do other stuff

Case Else
' Ignore anything else

End Select
</code>


"Charles Law" <bl***@nowhere.com> wrote in message
news:el**************@TK2MSFTNGP15.phx.gbl...
Hi Mattias

I could write it as all uppercase, but I prefer to see it as mixed case
as

I
find it more readable. Also, the test then becomes dependent on the case

of
the string. Ideally, there would be a way of making Select ... Case

perform
a case insensitive test.

Charles
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
> ><code>
>> Select Case e.Tool.Key.ToUpper
>> Case "FirstOption".ToUpper
>> ' Do stuff
>>
>> Case "SecondOption".ToUpper
>> ' Do other stuff
>>
>> Case Else
>> ' Ignore anything else
>>
>> End Select
>></code>
>
> Why all the ToUpper calls? Why don't you simply do
>
> Case "SECONDOPTION"
>
> instead? I'm not sure if that will get rid of the FxCop warnings
> though.
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.



Nov 21 '05 #3

P: n/a
Thanks as usual Herfried.

They don't call me Mr Short-sighted, Doesn't Look Where He's Going for
nothing ;-)

Charles
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O4**************@TK2MSFTNGP10.phx.gbl...
"Charles Law" <bl***@nowhere.com> schrieb:
I could write it as all uppercase, but I prefer to see it as mixed case
as I find it more readable. Also, the test then becomes dependent on the
case of the string. Ideally, there would be a way of making Select ...
Case perform a case insensitive test.


Take a look at 'Option Compare {Text, Binary}'.

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

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.