我有一个List,我依旧在一个属性上订购.
不幸的是,数据库设置(我猜)在获取数据时没有正确处理国家字符.虽然我不能改变(不是我的数据库),所以我需要直接解决这个问题.因此,我简化了下面的例子.
var x1 = new Shop() {city = "Århus"};
var x2 = new Shop() { city = "Ans" };
var x3 = new Shop() { city = "Balle" };
list.Add(x1);
list.Add(x2);
list.Add(x3);
list = list.OrderBy(a => a.city).ToList();
//Result:
// Århus, Ans, Balle
// Should be:
// Ans, Balle, Århus
Run Code Online (Sandbox Code Playgroud)
这些评论应该解释我的问题:"Å"是丹麦字符集中的最后一个字母
我无法控制应用程序设置,但是我可以强制OrderBy使用特定的字符集进行排序吗?
提前致谢,
斯蒂恩佩德森
我想加载一个通用列表.因此我想使用如下函数:
public static <T> List<T> load()
{
FileInputStream fileStream = null;
List<T> toReturn = new ArrayList<T>();
String fileExtension = toReturn.getClass().getComponentType().getSimpleName();
...
}
Run Code Online (Sandbox Code Playgroud)
如果你能看到我想获得Type("T"),搜索带有这些扩展名的文件.但如果我打电话:
StorageUtil.<MyClass>load();
Run Code Online (Sandbox Code Playgroud)
我得到一个Exception,而不是将"MyClass"作为fileExtension.我的代码出了什么问题?
我有一个PlaceInfo包含类型的私有字段的类Result.在PlaceInfo我的构造函数中取类型参数Result.
现在我的JsonConvert.DeserializeObject<SearchFind>(JsonData);发言为我提供Result[]了帮助res.Results.
我必须建造一个List<PlaceInfo>.
最简单和拇指逻辑的方式如下(我目前正在使用).
foreach (var serverPlace in res.Results)
lstPlaces.Add(new PlaceInfo(serverPlace));
Run Code Online (Sandbox Code Playgroud)
谁能建议我先进的结构?
我有一节课:
public class CounselPoints
{
public int CounselNum { get; set; }
public String CounselPoint { get; set; }
public bool BR { get; set; }
public bool ICRVBS { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
......以及该类的通用列表:
List<CounselPoints> counselPoints = AYttFMConstsAndUtils.DeserializeCounselPointsFile();
Run Code Online (Sandbox Code Playgroud)
我想从该通用列表中检索下一个适当的CounselPoint,其逻辑可以用SQL表示,如下所示:
SELECT TOP 1 CounselNumber
FROM COUNSELPOINTSLU
WHERE BR IS TRUE
AND CounselNumber > @LastCounselPoint;
Run Code Online (Sandbox Code Playgroud)
我把这种方法称为试图获得该值,并且像这样挥舞着它:
public static int GetNextBibleReadingCounselPoint(int LastCounselPoint)
{
List<CounselPoints> counselPoints = AYttFMConstsAndUtils.DeserializeCounselPointsFile();
return counselPoints.FirstOrDefault(i => i.CounselNum).Where(j => j.BR).Where(k => k.CounselNum > LastCounselPoint);
}
Run Code Online (Sandbox Code Playgroud)
在"英语"中,我试图说," 给我第一个比传入的arg(LastCounselPoint)更大数量的CounselNum,以及BR是真的 "
例如,如果我传入17,并且CounselNum值为18的counselPoint"记录"也将BR设置为true,则应该返回18.简单,不是吗? …
对于设置,我有:
interface Parent
interface Child1 extends Parent
interface Child2 extends Parent
Run Code Online (Sandbox Code Playgroud)
我在其他地方:
public class MyClass {
private List<Child1> child1List = new ArrayList<>();
public List<Parent> getChild1List(Contact contact) {
return child1List.parallelStream()
.filter(m -> m.getContacts().contains(contact))
.sorted(Comparator.comparing(Parent::getParentField))
.collect(Collectors.toList());
}
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,getChild1List返回一个List<Parent>(不应该返回List<Child1>吗?)
后来,我发现该流对其他方法很有用,所以我提取它并用它构建了一个泛型方法.我有多个扩展Parent的接口,所以我做了如下:
private <T extends Parent> List<T> returnsListByContact(List<T> childList, Contact contact) {
return childList.parallelStream()
.filter(m -> m.getContacts().contains(contact))
.sorted(Comparator.comparing(Parent::getParentField))
.collect(Collectors.toList());
}
Run Code Online (Sandbox Code Playgroud)
并getChild1List(Contact contact)成为:
public List<Parent> getChild1List(Contact contact) {
return returnsListByContact(child1List, contact);
}
Run Code Online (Sandbox Code Playgroud)
但是现在它不喜欢这个,引用getChild1List返回一个List<Child1>.我不明白为什么,因为流的实现根本没有改变 - 除了启动它的childList来自通用参数,而不是直接调用MyClass的私有成员字段.
那他们为什么要回归两件不同的东西呢?
我需要/想要[System.Collections.Generic.List[string]]从函数返回 a ,但它被包含在一个System.Object[]
我有这个
function TestReturn {
$returnList = New-Object System.Collections.Generic.List[string]
$returnList.Add('Testing, one, two')
return ,@($returnList)
}
$testList = TestReturn
$testList.GetType().FullName
Run Code Online (Sandbox Code Playgroud)
它将它作为 a 返回System.Object[],如果我将返回行更改为
return [System.Collections.Generic.List[string]]$returnList
Run Code Online (Sandbox Code Playgroud)
或者
return [System.Collections.Generic.List[string]]@($returnList)
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,当[System.String]列表中有一项时,它返回 a ,System.Object[]如果有多个项,则返回 a 。列表有什么奇怪的地方不能用作返回值吗?
现在,奇怪的是(我认为)如果我像这样键入接收值的变量,它确实有效。
[System.Collections.Generic.List[string]]$testList = TestReturn
Run Code Online (Sandbox Code Playgroud)
但这似乎是某种奇怪的强制转换,其他数据类型不会发生这种情况。
在https://docs.oracle.com/javase/tutorial/java/generics/upperBounded.html中,建议实现一个方法
public static double sumOfList(List<? extends Number> list) {
double s = 0.0;
for (Number n : list)
s += n.doubleValue();
return s;
}
Run Code Online (Sandbox Code Playgroud)
然后用它来调用它
List<Integer> li = Arrays.asList(1, 2, 3);
System.out.println("sum = " + sumOfList(li));
Run Code Online (Sandbox Code Playgroud)
public static <T> double sumOfList(List<T extends Number> list)?public static <T extends Number> double sumOfList(List<T> list)等价的吗?如果是的话,是不是风格不太好?System.out.println("sum = " + sumOfList<Integer>(li));?我真的无法修复我的代码,想知道是否有人可以帮助我.
基本上我得到以下错误:
找不到类型或命名空间名称"T"(您是否缺少using指令或程序集引用?)
以下是我的课程:
课程类别:
using System;
using System.Collections.Generic;
using System.Text;
namespace LinkedListGen
{
class program
{
public static void Main(string[] args)
{
LinkListGen<T> testList = new LinkListGen<T>();
Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
LinkGen类:
using System;
using System.Collections.Generic;
using System.Text;
namespace LinkedListGen
{
class LinkGen<T>
{
private T data;
private LinkGen<T> next;
public LinkGen(T item)
{
data = item;
next = null;
}
public LinkGen(T item, LinkGen<T> list)
{
data = item;
next = list;
}
public LinkGen<T> TailList
{
set …Run Code Online (Sandbox Code Playgroud) 我有一个字符串[],其中包含值{"data1","data2","data3"}.
我有一个包含的GenericList
DATA2
DATA4
两条记录
我想获得在string []和genericList中可用的公共数据
以下两种方法可以很好地编译并完成它们的功能.
public int returnArray()[]
{
int a[]={1 ,2};
return a;
}
public String[] returnArray(String[] array[])[]
{
return array;
}
Run Code Online (Sandbox Code Playgroud)
根据这个方法签名,我们不能以某种方式有如下方法签名吗?
public <T>List rerurnList(List<T> list)<T>
{
return new ArrayList<T>();
}
Run Code Online (Sandbox Code Playgroud)
此方法旨在返回java.util.List泛型类型.它不编译.必须按如下方式对其进行修改才能成功编译.
public <T>List<T> rerurnList(List<T> list)
{
return new ArrayList<T>();
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我们不能像第一种情况那样有方法签名吗?
generic-list ×10
c# ×4
generics ×4
java ×3
lambda ×2
linq ×2
java-8 ×1
linked-list ×1
list ×1
methods ×1
powershell ×1
return-type ×1