Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Console App able to have property?

Posted on 2008-11-02
6
Medium Priority
?
210 Views
Last Modified: 2012-05-05
Hi,

Can my console app have a property? or is there another way i can have a global type variable?

The code below fails to build.

thanks,


class Program
{
	internal StringBuilder MessageLog = new StringBuilder();
	static void Main(string[] args)
	{
		this.Messagelog.AppendLine("Hello World");
	}
}

Open in new window

0
Comment
Question by:Valimai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22865089
yes your console application can definitely have a property defined but from where and how you want to access it
can you please state what your actual requirement is so that we can help you out better
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22865274
Example of how you can do it ...
namespace ConsoleApplication3
{
 
    class Program
    {
        class GlobalVars
        {
            public StringBuilder MessageLog = new StringBuilder();
        }
 
        static void Main(string[] args)
        {
            GlobalVars myGlobalVariables = new GlobalVars();
            myGlobalVariables.MessageLog.Append("Test");
        }
    }
}

Open in new window

0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 1000 total points
ID: 22865510
Another way you can do it, add 'static' keyword:
internal static StringBuilder MessageLog = new StringBuilder();
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 18

Assisted Solution

by:philipjonathan
philipjonathan earned 1000 total points
ID: 22865514
Uh, and use Program to refer to the property instead of 'this':
Program.Messagelog.AppendLine("Hello World");
0
 
LVL 1

Author Comment

by:Valimai
ID: 22871846
Hi Philip,

I used
internal static StringBuilder MessageLog = new StringBuilder();
and refered to it as just
MessageLog.AppendLine();

thank you very much.
0
 
LVL 18

Expert Comment

by:philipjonathan
ID: 22872822
Yes, you can do that as long as you are referring to the MessageLog from within the Program class scope
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question