English 中文(简体)
B. 在订购数据时操纵行为
原标题:String behaviour during ordering data

在我的申请中,我从网站下载了一些数据,提供人口、地貌地区等地貌信息。

After parsing html code, data are stored in list of objects

public class Landscape
{
    public int Population { get; set; }
    public string Area { get; set; }
}

public List<Landscape> data;

没有问题。 跟踪填充数据的方法以及我申请的目的。 现在,问题在哪里? 该网站的“区域信息”采用半数字、半指示格式。 例如:10 000平方公里

I have possibility to choose whether to trim km2 suffix and store data as int, or do nothing about it and store data as string. Since I want have data in dataGrid in original format, I decided not to trim.

最后,是否有一个路要订购(面积大小)as int,尽管其位置是类型?

最佳回答

你们可以使用支线,按翻译价值进行分类,但认为这样做不会很快。

public class Landscape
{
    public int Population { get; set; }
    public string Area { get; set; }

    public int TrimAndConvert()
    {
        /* Your Code to trim and convert to int */
    }
}


data.OrderBy(landscape => landscape.Area.TrimAndConvert());

我认为,更好的办法是把“区域”作为数目,只增加产出的三分之一。

public class Landscape
{
    public int Population { get; set; }
    public int AreaValue { get; set; }
    public string AreaUnit { get; set; }

    public string Area 
    {
        get 
        {
            return AreaValue.ToString() + AreaUnit;
        }
    }
}
问题回答

您将需要采用国际竞争委员会的一种方法/有效载荷,使用国际竞争委员会。

这应当使你开始:

http://msdn.microsoft.com/en-us/library/234b841s.aspx” rel=“nofollow”>List<T>Sortmeth (IComparer<T>>





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签