Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

public variables C# and C++

Posted on 2006-11-10
2
Medium Priority
?
244 Views
Last Modified: 2010-04-16
Moving from C++ to C# one of many annoying "features" is the need to use the the word  "public" in front of public variables.
I like to comment my code at the same time limit my typing workload.

In this C# Example:  I can limit my need to type public by declaring the public variables on the same line using a comma separator.

public int A; // comment about variable A
public int X1, Y1, Z1, W1, T1; // comments about Variables X1, Y1, Z1


Where as in C++ I can use one public statement and neatly comment each variable.

public:
       int X1;  // this is a comment about variable X1
       int Y1;  // this is a comment about variable Y1
       int Z1;  // this is a comment about variable Z1
       int W1; // this is a comment about variable W1
       int T1;  // this is a comment about variable T1

My Question:
Is there a way to group public variable in C# ?

Maybe I'm just to picky!
0
Comment
Question by:hansw77041
2 Comments
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 2000 total points
ID: 17919854
Whereas I'd make the counterargument: in C# (and Java, for that matter) looking at any declaration I immediately know the scope of the variable, which is of more immiediate utility than almost any comment I've ever seen on a variable.  (-:

Granted that's overstating it a little, but there is a good reason for requiring each variable be explicitly declared.

If it's absolutely necessary to split them up, just put the variables on separate lines:

public int X1,
                  X2,
                  X3
;

0
 

Author Comment

by:hansw77041
ID: 17919874
Thanks... obvious but I missed it ! :-)
0

Featured Post

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.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

772 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