This is my first post in D.I.C.
I was just wondering which method of comparing 2 (int) values is more efficient, using the Conditional Operator, or the CompareTo() Method.
Below, is my code. I've tested it both ways (using ?: and using CompareTo(), and they both work. I am just wondering if there is a difference, more "preferred" way etc.
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
int width = ClientRectangle.Width;
int height = ClientRectangle.Height;
int maxhw;
Pen penf = new Pen(Color.Orange);
penf.Width = 1;
//
// This: maxhw = width.CompareTo(height) == 1 ? width : height;
// <--OR-->
// This: maxhw = width > height ? width : height;
//
for (int i = 25; i <= maxhw; i += 25)
{
penf.Color = i % 50 == 0 ? Color.LightSteelBlue : Color.Orange;
penf.Width = i % 100 == 0 ? 2 : 1;
e.Graphics.DrawLine(penf, i, 0, i, height); // draw vertical gridlines
e.Graphics.DrawLine(penf, 0, i, width, i); // draw horizontal gridlines
}
Thanks for taking time to read my post.
Paul

New Topic/Question
Reply




MultiQuote






|