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

C# Help: configurationmanager.appsettings

P: n/a
I've been using VB 2005 for a few years now. My entire coding history is
VB related.

This weekend I decided to start learning C#. I'm at work now and decided
to do some coding in C# that I would normally do in VB. I'm running into
various 'small' difficulties.

I don't understand this:

In vb, this is valid:

Dim strConnection as string
strConnection = ConfigurationManager.AppSettings("miscellaneous")

But, when I attempt to do similar with C#:

string strConnection;
strConnection = ConfigurationManager.AppSettings("miscellaneous");

I don't get any errors during design time. When I save the page (and
code behind), and attempt to load it, I get this error:

Compiler Error Message: CS0118:
'System.Configuration.ConfigurationManager.AppSett ings' is a 'property'
but is used like a 'method'

How should it go then?

TIA,
Jim
Feb 20 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Jimmy,

Vb has the same syntax for iterators and functions. C# doesn't. Because
AppSettings is an iterator property, you should write:

string strConnection = ConfigurationManager.AppSettings["miscellaneous"];

--
Milosz
"Jim in Arizona" wrote:
I've been using VB 2005 for a few years now. My entire coding history is
VB related.

This weekend I decided to start learning C#. I'm at work now and decided
to do some coding in C# that I would normally do in VB. I'm running into
various 'small' difficulties.

I don't understand this:

In vb, this is valid:

Dim strConnection as string
strConnection = ConfigurationManager.AppSettings("miscellaneous")

But, when I attempt to do similar with C#:

string strConnection;
strConnection = ConfigurationManager.AppSettings("miscellaneous");

I don't get any errors during design time. When I save the page (and
code behind), and attempt to load it, I get this error:

Compiler Error Message: CS0118:
'System.Configuration.ConfigurationManager.AppSett ings' is a 'property'
but is used like a 'method'

How should it go then?

TIA,
Jim
Feb 20 '07 #2

P: n/a
Hi Jimmy,

Vb has the same syntax for indexers and functions. C# doesn't. Because
AppSettings is an indexer property, you should write:

string strConnection = ConfigurationManager.AppSettings["miscellaneous"];

--
Milosz
"Milosz Skalecki [MCAD]" wrote:
Hi Jimmy,

Vb has the same syntax for iterators and functions. C# doesn't. Because
AppSettings is an iterator property, you should write:

string strConnection = ConfigurationManager.AppSettings["miscellaneous"];

--
Milosz
"Jim in Arizona" wrote:
I've been using VB 2005 for a few years now. My entire coding history is
VB related.

This weekend I decided to start learning C#. I'm at work now and decided
to do some coding in C# that I would normally do in VB. I'm running into
various 'small' difficulties.

I don't understand this:

In vb, this is valid:

Dim strConnection as string
strConnection = ConfigurationManager.AppSettings("miscellaneous")

But, when I attempt to do similar with C#:

string strConnection;
strConnection = ConfigurationManager.AppSettings("miscellaneous");

I don't get any errors during design time. When I save the page (and
code behind), and attempt to load it, I get this error:

Compiler Error Message: CS0118:
'System.Configuration.ConfigurationManager.AppSett ings' is a 'property'
but is used like a 'method'

How should it go then?

TIA,
Jim
Feb 20 '07 #3

P: n/a
Milosz Skalecki [MCAD] wrote:
Hi Jimmy,

Vb has the same syntax for indexers and functions. C# doesn't. Because
AppSettings is an indexer property, you should write:

string strConnection = ConfigurationManager.AppSettings["miscellaneous"];
Hmm. Well, I never said I didn't have a long ways ago, which I certainly
do.

I've grown to love vb over the years but one of my biggest issues is
that most of the code samples and 'helpers' that I'm seeing out there
now a days revolves around C#. So, I figured it's finally time to just
learn it. Also, I figure that if I learn C#, I can (more) easily figure
out C/C++/Java if need be.

Thanks.
Feb 20 '07 #4

P: n/a
Good decision ;-)
--
Milosz
"Jim in Arizona" wrote:
Milosz Skalecki [MCAD] wrote:
Hi Jimmy,

Vb has the same syntax for indexers and functions. C# doesn't. Because
AppSettings is an indexer property, you should write:

string strConnection = ConfigurationManager.AppSettings["miscellaneous"];

Hmm. Well, I never said I didn't have a long ways ago, which I certainly
do.

I've grown to love vb over the years but one of my biggest issues is
that most of the code samples and 'helpers' that I'm seeing out there
now a days revolves around C#. So, I figured it's finally time to just
learn it. Also, I figure that if I learn C#, I can (more) easily figure
out C/C++/Java if need be.

Thanks.
Feb 20 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.