|
I've always done it this way :
public string Name
{
get
{
}
set
{
}
}
even if the codes are only 1 line long. I know it makes my coded bloated but i figure, that's what the collapsing options are there for. Besides, they're much easier to read.
God, I pity me! - Phoncible P. Bone
If I end up Windows ME someone is going to be hurting. - One of the answers to a question for What OS are you
|
|
|
|
|
I'm with Nick, each brace on its own line no matter the amount of code within the get/set.
But I explicitly define regions around the code block; which I don't know if Nick does.
#region Public Properties
#region MyProp
public type MyProp
{
get
{
return myProp;
}
set
{
myProp = value;
}
}
#endregion
#region SecondProp
public t2 SecondProp
{
get
{
...
}
set
{
...
}
}
#endregion
#endregion This formats everything rather nicely so I can view just the properties and methods I want while looking at the source.
James
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
I would maybe skip the #region bit for every single property, since they are easily collapsed anyway...
|
|
|
|
|
James T. Johnson wrote:
I explicitly define regions around the code block
I think that an implicit region is defined for each Method (or attribute, in this case),
so you might not need to do that....
I use regions to group members with similar characteristics, like
<br />
#region Private Fields<br />
#endregion<br />
<br />
#region Public Attributes<br />
#endregion<br />
<br />
#region Public Static Methods<br />
#endregion<br />
<br />
#region Constructors<br />
#endregion<br />
<br />
and so on
F.O.R.
|
|
|
|
|
|
Frank Olorin Rizzi wrote:
I think that an implicit region is defined for each Method (or attribute, in this case),
so you might not need to do that....
Correct, but if you have any Attributes or comments above the method or prperty then you have another block to expand/collapse. This way I still have only one region to expand to see everything and on region to collapse when I'm done.
And for whatever reason I never liked the (...) it appends
James
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
James T. Johnson wrote:
And for whatever reason I never liked the (...) it appends
[g]Agreed, but I hate the fact that it collapses blank lines ![/g]
F.O.R.
|
|
|
|
|
I vary...
I usually do:
string Name
{
get
{
return m_name;
}
set
{
if(m_name == value) return;
m_name = value;
UpdateSomething();
}
}
(Note on the side: I put the return statement on the same line as the if, since it isn't braced.)
But when I have properties where both the get/set are one-liners, I either use:
string Name
{
get{return m_name;}
set{m_name = value;}
}
or when there are a lot of them, I may even:
string Firstname{ get{return m_firstname;} set{m_firstname = value;} }
string Lastname{ get{return m_lastname;} set{m_lastname = value;} }
string Address{ get{return m_address;} set{m_address= value;} }
I always know that if I used the latter, that its just setting a similarily named membervariable, and no special logic...
|
|
|
|
|
Well i like the first one... with a minor modificataion... Since i like the gull-wings (swedish translation) on the same row as the code, (java-style).
String Name{
get { return m_name; }
set{
if (m_name == value)
return;
m_name = value;
UpdateSomething();
}
}
|
|
|
|
|
I do the "inconsistent" way:
<br />
public string Name<br />
{<br />
get { return _name; }<br />
set<br />
{<br />
return x;<br />
}<br />
}<br />
might be inconsistent,
but I don't think it's too bad...
..after all, the get and set are truly two separate methods,
so if you look at them separately, they end up being consistent
with the rest of the code (where I generally have on one line ONLY the one-liner methods)..
F.O.R.
PS: Then again, it's all style, and that's all about personal preference, right?
|
|
|
|
|
The get and set will always have to have the braces. But
the real problem here is that if the code after a if or what ever
is more than one line then anything after that will not be run.
public string Name
{
set
{
if ( m_name != value )
m_name = value;
m_name.Validate;
}
}
That is why I do like you do because it makes the more readable
and the intent is clearly there. I have seen code that has this
kind of style thru out and it is hard to read.
public string Name
{
get
{
if ( m_name != value )
{
m_name = value;
m_name.Validate;
}
}
}
Bo Hunter
<marquee behavior="alternate">Bo Hunter
|
|
|
|
|
It's not about C# but rather about reading: if You can read using "quick" method (I don't know about it's name in English) e.g You can see all the page (screen) (impossible to remember) the easier way is:
if(...) ...; else ...;
get { ... };
But if You use "standard" method (You can see only few letters, but have better memory) the better way is:
if(...)
...;
else
...;
set
{
...
}
So - Dijkstra, Kerningham etc. couldn't read with "quick" method. It's all. Sorry for my language.
Hi,
AW
|
|
|
|
|
Hey, I am creating an alarm clock in c#. I want to create a event that calls a method to , lets say tell the user what time it is. I tried to read all tutorials on events and delegates. Still, I have no idea how to implement things. can anybody show me a very simple example?
"To teach is to learn twice"
|
|
|
|
|
public delegate void TimerEventHandler(object sender, TimerEventArgs e);
public class TimerEventArgs : EventArgs
{
}
public event TimerEventHandler TimerRing;
protected OnTimerRing(TimerEventArgs e)
{
if(TimerRing!=null) TimerRing(this,e);
}
private void TimerRung(object sender, TimerEventArgs e)
{
}
AlarmClock.TimerRing+=new TimerEventHandler(this.TimerRung);
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I will submit a complete tutorial in next 1 or 2 days.
I will completely clarify them from scratch.
So, hold on just 1 or 2 days
Thanx
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Go to help search in your .net IDE and search for "AlarmClock". Microsoft created a tutorial on it.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I'm currently using ODP.NET (Oracle Data Provider) to connect to an oracle database. Is there a replacement control for ADODC (to go to the previous and next records) or do i have to create buttons myself for the navigational purposes?
|
|
|
|
|
create the buttons and modify the BindingCOntext.Position property
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
private bool switchMC=true;
private void mButton(object sender, System.EventArgs e)
{
Button btn = null;
if(switchMC==true)
{
btn=(Button)sender;
btn.Text="1";
switchMC=false;
}
else if(switchMC==false)
{
btn=(Button)sender;
btn.Text="0";
switchMC=true;
}
}
I'm not sure if I'm giving enough information here...
When I run this, it takes 2 clicks to get the else if statment to run...
How can I get it to 1?
/\ |_ E X E GG
|
|
|
|
|
Hmmmm, just remove the "else"?
Regards,
Alvaro
If you want to get to the top, prepare to kiss a lot of bottom. -- despair.com
|
|
|
|
|
Your code works fine here, on loading the button text is whatever is has been set to in the designer, on the first click the text changes to "1", then next click it changes to "0", then to "1" and so on and so forth..
I'm not sure what it is you want to achieve, but if you wanted the button text to be "1" before clicking it, you would need to invoke your button click event handler somewhere beforehand, for example:
mButton(this.button1, null);
|
|
|
|
|
Sorry, I didn't explain enough...
There are 7 different buttons that use that method.
They all start out at 0.
Now, try the code out and see what it does... It's rather hard to explain...
/\ |_ E X E GG
|
|
|
|
|
Well, the thing is...
try it with 7 diffent buttons which all use mButton for their on_click...
It get's weird results... just try it out real fast...
/\ |_ E X E GG
|
|
|
|
|
Is your btn.Text initailly set to "1"? You have the initial value of switchMC as true, so the first time through it will go through the "True" condition and the next time it will go through the "False" condition.
Also, you do not need the second "IF" since you are using an ELSE, the ELSE will only be reached if switchMC is not true so you do not need the addition test. You could also restructure the code to either:
Button btn = (Button) sender;
if(switchMC)
{
btn.Text="1";
switchMC=false;
}
else
{
btn.Text="0";
switchMC=true;
}
Or
Button btn = (Button) sender;
btn.Text = switchMC ? "1" : "0";
switchMC=!switchMC;
Rocky Moore <><
|
|
|
|
|
I have 7 buttons that use the code for their on_click...
they are all initially set to 0...
/\ |_ E X E GG
|
|
|
|