Solved

public variables C# and C++

Posted on 2006-11-10
2
218 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Offline Apllication 5 72
About delegates in c sharp 3 47
free scanner TWAIN can be operated with a Web application 9 61
InputLanguage 1 26
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

810 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