Solved

public variables C# and C++

Posted on 2006-11-10
2
214 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 500 total points
Comment Utility
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
Comment Utility
Thanks... obvious but I missed it ! :-)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now