Solved

public variables C# and C++

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - SQL Timeout 9 50
insert value of checklistbox checked 4 39
How do I hide MVVM menu items in WPF/XAML? 1 33
Please explain purpose of GZIP 4 58
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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