我如何使用LINQ返回一个国家列表,但将某个特定国家放在顶部?(How can I use LINQ to return a list of Countries but place a particular country aribitrarly at the top?)
我有一张表格,其中包含我用来填充下拉列表的国家/地区列表。
我如何构建一个LINQ查询,以便按照字母顺序返回该表中的国家/地区列表,除了将美国置于顶端?
所以,如果表格包含:
瑞典
美国
墨西哥
丹麦它会返回:
美国
丹麦
墨西哥
瑞典?
I have a table with a list of countries in it that I'm using to populate a dropdown.
How can I construct a LINQ query so it will return the list of countries from that table in alphabetical order, with the exception of placing USA at the top?
So, if the table contained:
Sweden
USA
Mexico
DenmarkIt would return:
USA
Denmark
Mexico
Sweden?
原文:https://stackoverflow.com/questions/989290
最满意答案
我现在这样做了:
[libraryCell.myView bind:@"amount" toObject:libraryCell withKeyPath:@"objectValue.amount" options:nil]; [libraryCell.myView bind:@"max" toObject:_librariesController withKeyPath:@"arrangedObjects.@max.amount" options:nil];
因此myView中有两个属性(数量和最大值),当它们中的任何一个发生变化时,我会进行计算并相应地更新显示。
I've now done this like so:
[libraryCell.myView bind:@"amount" toObject:libraryCell withKeyPath:@"objectValue.amount" options:nil]; [libraryCell.myView bind:@"max" toObject:_librariesController withKeyPath:@"arrangedObjects.@max.amount" options:nil];
There are thus two properties in myView (amount and max) and when either of them change I do the calculation and update the display accordingly.
相关问答
更多-
你必须切换到这个: array = [[1,5],[3,5],[6,7],[8,7],[25,25],[26,50]] n = len(array) for i in range(n-1): if abs(array[i][1] - array[i+1][1]) >= 10: arr1 = array[:i+1] arr2 = array[i+1:] you have to switch to this: array = [[1,5],[3,5],[6,7],[8, ...
-
我现在这样做了: [libraryCell.myView bind:@"amount" toObject:libraryCell withKeyPath:@"objectValue.amount" options:nil]; [libraryCell.myView bind:@"max" toObject:_librariesController withK ...
-
语法Bands[0]是一个索引器访问。 索引器是一个具有参数的属性。 C#不允许通过名称来访问具有参数的属性,但允许索引器语法的属性与DefaultMemberAttribute在类型类型中给出的名称匹配。 要在您的示例中获取索引器的PropertyInfo ,您可以编写: PropertyInfo nestedProperty = property.PropertyType.GetProperty("Bands"); var defaultMember = (DefaultMemberAttribute) ...
-
像这样的东西应该工作: with mytable as ( select 1 as id, array[1, 2, 3, 4] as myarray union all select 1 as id, array[5, 6] as myarray union all select 1 as id, array[7, 8] as myarray ) select id, array_agg(elements order by elements) from mytable, unnest(m ...
-
函数向数组项添加空格(function adding space to array item)[2024-01-16]
你误解了filter工作原理。 从精细手册 : filter()方法创建一个新数组,其中包含通过所提供函数实现的测试的所有元素。 回调的返回值告诉filter应该通过哪些classNames元素,只测试返回值的真实性。 filter不返回回调的返回值, classNames中的原始未触摸值是。 所以问题不在于增加了额外的空间,问题在于没有任何东西正在移除空间。 如果您想同时进行测试和修改,那么reduce会更好地为您服务: return classNames.reduce(function(a, class ... -
创建一个JavaScript对象,该对象抓取每个数组项并对其进行整理(Creating a JavaScript object that grabs each array item and collates it)[2024-02-20]
var services = []; businessData.forEach(function (business) { Array.prototype.push.apply(services, business.services); }); 你几乎就在那里,但是你正在将一系列服务推向一个数组。 通过使用Array.prototype.push.apply,我们将服务推送到数组。 最终会给你你想要的结果:) var services = []; businessData.forEach(fu ... -
如果汽车检查发动机属性并允许它或不成为汽车的一部分,这是一个问题吗? 没有。 话虽这么说,您的验证可能足够复杂,以引入域服务。 由于涉及两个聚合,您可以这样: car.Fit(engine) 或这个: engine.Fit(car) 但是,你可能想要检查汽车模型:) 由于规则会更先进并涉及一些数据,您可能想要引入域服务并可能在对象上使用双重调度: 所以而不是car.Fit(engine)你可以这样: car.Fit(engine, IModelServiceImplementation) 并在Fit方 ...
-
这是我能想出的最实用的方法。 这包括聚合和您想要的转换: var arr2 = Object.keys(arr2 = arr1.map(function(item) { return item.status; }).reduce(function(acc,curr){ acc[curr] = acc[curr] + 1 || 1; return acc; }, [])).map(function(item){ return {key: item, value: arr2[it ...
-
使用find获取对象,然后使用找到的对象的索引来替换元素 // Create array var schedule = []; schedule.push({ 'action': 'add', 'id': 1 }); schedule.push({ 'action': 'update', 'id': 2 }); // Find array object var searchId = 2; var foundObj = schedule.find(function(obj) { return ...
-
根据项目的某些属性将数组拆分为数组数组(Break an array to array of arrays based on the some of item's property)[2023-03-16]
一个使用数组进行计数的提议,它使用所有空格,而不仅仅是最后一个空格。 var data = [{ id: 0, width: 2 }, { id: 1, width: 2 }, { id: 2, width: 4 }, { id: 3, width: 1 }, { id: 4, width: 3 }], max = 4, grouped = []; data.forEach((count => a => { var index = count.findIndex(b => ...