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
Solved

public variables C# and C++

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Close form "before" open 3 48
FTP file download using c# 3 25
tableview is not updating 1 20
"Emulate" TAB key when press Enter Key 3 44
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

789 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