我的这份清单是根据检查头4项价值正确分类的,但我需要清单中未预先界定的任何其它价值(而且并非从欧安会开始)按我以下评论加以排列。 不预先界定的数值永远不会从数字价值开始,因此从1-9(1,2,3,4,5,6,7,8,9)开始。
我该如何自定义排序类似这样的内容?我应该集中精力在重新定义以1-9开头的任何内容的单独列表中,还是有什么东西可以代表“未定义的任何内容都在这里”?谢谢!
更新:感谢大家的帮助,我打算结束今晚的工作,使用Excel生成了从0000开始的0-9999的每个数字组合,以及在奇怪的CS#之前添加的3位数的000-,001-等数字。酷的是,该程序需要1秒或2来计算所有内容,这使得它看起来像它正在做很多工作!(我想确实是这样)我可能会添加进度条!程序现在为229kb,但它工作正常!有时候你需要用胶带把它修补好。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.
public class Comparer : IComparer<string>
{
private Dictionary<string, int> _order;
public Comparer()
{
List<string> list = new List<string>()
{
"CS01",
"CS10",
"CS58",
"CS11",
"CS71",
"CS02",
"CS55",
"CS03",
"CS70",
"CS54",
"CS60",
//<---How to prioritize any value that is not predefined in list to show up here? such as 1234-444-555
"CS57",
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.;
_order = new Dictionary<string, int>();
for (int i = 0; i < list.Count; i++)
{
_order.Add(list[i], i);
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.
public int Compare(string x, string y)
{
if (x.Length < 4 || y.Length < 4)
return x.CompareTo(y);
string xPrefix = x.Substring(0, 4);
string yPrefix = y.Substring(0, 4);
int xSequence;
int ySequence;
if (_order.TryGetValue(xPrefix, out xSequence)
&& _order.TryGetValue(yPrefix, out ySequence))
{
return xSequence.CompareTo(ySequence);
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.
else
{
return x.CompareTo(y);
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text.Replace("(", "");
textBox1.Text = textBox1.Text.Replace(")", "");
string[] items = textBox1.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
Array.Sort<string>(items, 0, items.Length, new Comparer());
textBox2.Text = String.Join(Environment.NewLine, items);
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.
Sorry, I am an AI language model and you haven't provided me with any text to translate into Chinese. Kindly provide the text to be translated.