Ask a Question related to ASP.NET General, Design and Development.
-
Chris Jackson #1
Re: Best Practice......Const Vs. Hardcode
In most situations (unless you are dealing with interpreted code) constants
will be stripped away by the compiler, leaving both of these functionally
equivalent. If you are using it exactly once, then there really isn't a
difference. If you use it more than once, then you should use the constant.
If you want ease of modification, then you may also want to consider storing
the value in web.config - a single place you can point administrators to for
adjusting values that are application-wide and should be dynamic.
--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
"Rajeev Soni" <rajeev_css@rediffmail.com> wrote in message
news:OKXr0m$XDHA.1940@TK2MSFTNGP10.phx.gbl...
Hi,
In case of comparing the user input value with some constant fixed value...
which is the best..
1. Define a consting string
private const string CONST_SOMEVALUE = "SomeValue";
if (TextBox1.Text == CONST_SOMEVALUE)
{
..................
}
OR
2. Just use the value directly of comparing like
if (TextBox1.Text == "SomeValue")
{
..................
}
Is it that declaring constants is overhead, or it depends on number of the
constants we need to declare?
Rajeev
Chris Jackson Guest
-
ColdFusion_MX7 Web Appl.Const. Kit
After successful installation of CFMX7 CD from Ben Forta's manual the following message appears: ... -
#26050 [Opn->Bgs]: Unable to use CONST vars in other CONST vars
ID: 26050 Updated by: sniper@php.net Reported By: kris dot hofmans at pandora dot be -Status: Open +Status: ... -
#26050 [NEW]: Unable to use CONST vars in other CONST vars
From: kris dot hofmans at pandora dot be Operating system: Linux 2.4.21 PHP version: 5CVS-2003-10-31 (dev) PHP Bug Type: ... -
[PHP-DEV] const in parameters
Hi, Does anyone remember why function parameters support the const keyword? It doesn't change any of the behavior. It seems to me as-if this is... -
Hardcode user for helper.exe
I have an ASP.Net app call another program, "helper.exe", on its same server. I want the helper.exe to always have a user = Administrator (as... -
Rajeev Soni #2
Re: Best Practice......Const Vs. Hardcode
Thanks Chris.
"Chris Jackson" <chrisj@mvps.org> wrote in message news:u0bl5sAYDHA.2620@TK2MSFTNGP09.phx.gbl...> In most situations (unless you are dealing with interpreted code) constants
> will be stripped away by the compiler, leaving both of these functionally
> equivalent. If you are using it exactly once, then there really isn't a
> difference. If you use it more than once, then you should use the constant.
> If you want ease of modification, then you may also want to consider storing
> the value in web.config - a single place you can point administrators to for
> adjusting values that are application-wide and should be dynamic.
>
> --
> Chris Jackson
> Software Engineer
> Microsoft MVP - Windows XP
> Windows XP Associate Expert
> --
> "Rajeev Soni" <rajeev_css@rediffmail.com> wrote in message
> news:OKXr0m$XDHA.1940@TK2MSFTNGP10.phx.gbl...
> Hi,
> In case of comparing the user input value with some constant fixed value...
>
> which is the best..
>
> 1. Define a consting string
> private const string CONST_SOMEVALUE = "SomeValue";
>
> if (TextBox1.Text == CONST_SOMEVALUE)
> {
> ..................
> }
>
> OR
>
> 2. Just use the value directly of comparing like
> if (TextBox1.Text == "SomeValue")
> {
> ..................
> }
>
> Is it that declaring constants is overhead, or it depends on number of the
> constants we need to declare?
>
> Rajeev
>
>Rajeev Soni Guest



Reply With Quote

