473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

C# Help: configurationmanager.appsettings

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
4 10941
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Debus | last post by:
Hi, I try to read a value from app.config file using this code: string s=System.Configuration.ConfigurationManager.AppSettings.ToString(); I got the compiler error: Error 1 The type or...
3
by: natasha | last post by:
Hello everybody, you can use ConfigurationManager.AppSettings.Set method (ConfigurationManager is in System.Web.Configuration namespace) to store a modified value from web.config. To be...
6
by: otto | last post by:
Hi, all: I would like to know one thing: Is it possible to access an environment variable (like PATH) from web.config file? Something like this: <appSettings> <add key="name"...
2
by: Peter Kirk | last post by:
Hi there is there any way to tell what .config file the property System.Configuration.ConfigurationManager.AppSettings is trying to access? I have a class which uses this property but no...
2
by: Johnny Jörgensen | last post by:
I don't get the ConfigurationManager object. All I want to do is store my application settings and retrieve them on the next run. I instantiate the Configuration: static private Configuration...
2
by: pantagruel | last post by:
Hi, I have a Visual studio 2005 project that runs as a Windows Service. In it I have declared that I am using System.Configuration. I have set one application setting for the service using the...
0
by: Tom | last post by:
This seems odd ... While debugging my application in VS2008, I can successfully retrieve values from my configuration file doing the following: string bla = ConfigurationManager.AppSettings; ...
3
by: amjad905 | last post by:
Hi, I have created some dynamic labels and some dynamic linkbuttons... those linkbuttons have addhandlers assigned to them... but in postback those buttons gets deleted... the code is shown...
12
by: =?Utf-8?B?ZGdvdw==?= | last post by:
I designed a "contact_us" page in visual web developer 2005 express along with EW2 after viewing tutorials on asp.net's help page. Features work like they should, but I cannot figure out how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.