Solved

public CompareField SortBy = CompareField.Name;

Posted on 2014-02-15
1
212 Views
Last Modified: 2014-02-16
Just trying to understand this line of code....

public CompareField SortBy = CompareField.Name;  just need a quick explanation...

from

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    class CarComparer : IComparer<Car>


    {
  
        
        public enum CompareField
  {
      Name,
      MaxMph,
      Horsepower,
      Price,
  }
       public CompareField SortBy = CompareField.Name;
 public int Compare(Car x, Car y)
        {
            switch (SortBy)
            {
                case CompareField.Name:
                    return x.Name.CompareTo(y.Name);
                case CompareField.MaxMph:
                    return x.MaxMph.CompareTo(y.MaxMph);
                case CompareField.Horsepower:
                    return x.Horsepower.CompareTo(y.Horsepower);
                case CompareField.Price:
                    return x.Price.CompareTo(y.Price);
            }
            return x.Name.CompareTo(y.Name);
        }
        }
    }
}

Open in new window

0
Comment
Question by:yguyon28
1 Comment
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39862391
It's a public variable of type CompareField (an enum). It is being initialized to the Name member of the CompareField enum.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.NET Error 7 42
How do I get the id from URL? 19 47
c# code 19 58
Office.Interop.Word Document - Detect Macros not working 16 24
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now