can you make args that are passed upon runtime in C# global?

35 pts.
Tags:
C#
C# 2008
I have an app that needs to set the connectionstring based upon an arg that is passed at runtime.  I would like to access that argument in any method to create the connectionstring instead of having to pass the value to every method as some methods have quite a few variables passed to it.  Since this value will be the same whereever it's called, it can be set once and just be referenced when needed.

Does this make sense?



Software/Hardware used:
C# 2008 Express Edition

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    How about adding a member variable to your class, to store the connection string ?
    69,160 pointsBadges:
    report
  • Cathryn
    I'm more of a vb developer so what would that look like? Right now I have Main (string args[]) I use the last param to tell which server. So you are saying I can set the connection string in main to a member variable and I would be able to access that variable from any method? Do you know where I could see a simple example of how that looks?
    35 pointsBadges:
    report
  • carlosdl
    I'm not a C# developer either, but I think it would be something like this:
        class Program
        {
            private string m_ConnectionString;
    
            public string ConnectionString
            {
                get
                {
                    return m_ConnectionString;
                }
                set
                {
                    m_ConnectionString = value;
                }
            }
            static void Main(string[] args)
            {
                Program yourProgram = new Program();
                yourProgram.ConnectionString = args[0];
                yourProgram.SomeMethod();
            }
    
            void SomeMethod()
            {
                string con = ConnectionString;
                //do something
            }
    
        }
    }
    
    69,160 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following