C# Help: configurationmanager.appsettings

  • Thread starter Thread starter Jim in Arizona
  • Start date Start date
J

Jim in Arizona

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.AppSettings' is a 'property'
but is used like a 'method'

How should it go then?

TIA,
Jim
 
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"];
 
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 said:
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 said:
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.AppSettings' is a 'property'
but is used like a 'method'

How should it go then?

TIA,
Jim
 
Milosz said:
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.
 
Good decision ;-)
--
Milosz


Jim in Arizona said:
Milosz said:
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.
 
Back
Top