我正在用C#编写一个工具来查找重复的图像.目前我创建了文件的MD5校验和并进行比较.
不幸的是我的图像可以
什么是解决这个问题的最佳方法?
我有以下结构
List<string[]> sList = new List<string[]>() {
new[] { "x", "xxx", "xxxx" }, //1,3,4
new[] { "x", "xx", "xx" }, //1,2,2
new[] { "xxxxxx", "xx", "xx" } //6,2,2
};
Run Code Online (Sandbox Code Playgroud)
我需要string.length
按列确定项目的最大值
在此示例中,预期结果应为:
List<int> Result = new List<int>() { 6, 3, 4 };
Run Code Online (Sandbox Code Playgroud)
有一个简单的Linq方法吗?
我的努力(工作但不使用Linq):
List<int> Result = new List<int>();
foreach (string[] line in Table)
{
for (int i = 0; i < line.Length; i++)
{
if (Result.Count > i)
{
if (Result[i] < line[i].Length)
{
Result[i] …
Run Code Online (Sandbox Code Playgroud) 我有一个字符串
string Text = "012345678901234567890123456789";
Run Code Online (Sandbox Code Playgroud)
和一个List<int>
索引
List<int> Indexes = new List<int>() { 2, 4, 7, 9, 15, 18, 23, 10, 1, 2, 15, 40 };
Run Code Online (Sandbox Code Playgroud)
有以下限制
Text.length
从文本中删除索引列表中字符的最佳方法是什么?
预期产量:
035681234679012456789
Run Code Online (Sandbox Code Playgroud)
有没有比这更有效的方式了
foreach (int index in Indexes
.OrderByDescending(x => x)
.Distinct()
.Where(x => x < Text.Length))
{
Text = Text.Remove(index, 1);
}
Run Code Online (Sandbox Code Playgroud)
更新:以下是当前答案的基准(string
100.000个字符List<int>
,长度为10.000:
Gallant: 3.322 ticks
Tim Schmelter: 8.602.576 ticks
Sergei Zinovyev: 9.002 ticks
rbaghbanli: 7.137 ticks
Jirí Tesil Tesarík: 72.580 …
Run Code Online (Sandbox Code Playgroud) 我期待在这里找到一个关于这个的现有问题,但我没有.
Bitarray
当你可以将bool
值存储在一个时,使用a有什么好处bool[]
?
System.Collections.BitArray biArray = new System.Collections.BitArray(8);
biArray[4] = true;
bool[] boArray = new bool[8];
boArray[4] = true;
Run Code Online (Sandbox Code Playgroud)
的bool[]
,因为存在更多的(扩展)方法以数组,而不是一个工作似乎有点更加得心应手给我BitArray
您可以使用
List<string> sList = new List<string>() { "1", "2" };
Run Code Online (Sandbox Code Playgroud)
创建一个新列表并添加2个项目.该{ "1", "2" }
双组分只能是因为List<T>
已经实施了Add()
方法.
我的问题:{}
类似于操作员,可以重载,例如两次添加项目
假设我有以下输入:
string input = "123456789";
Run Code Online (Sandbox Code Playgroud)
并期望以下输出:
string output = "741852963";
Run Code Online (Sandbox Code Playgroud)
逻辑是一个正方形,需要向右旋转90度 - 但没有换行符.
// squares
//INPUT OUTPUT
// 123 ??? 741
// 456 V 852
// 789 963
Run Code Online (Sandbox Code Playgroud)
宽度应始终是动态的
int width = (int)Math.Sqrt(input.Length);
Run Code Online (Sandbox Code Playgroud)
有一个简单的方法来解决这个问题吗?
目前我有两种方式:
当我设置我的web.config cookieless="UseCookies"
我的网址看起来:
<sessionState timeout="60" cookieless="UseCookies"/>
当我设置cookieless="true"
我有这样的网址
http://example.com/%28S%28uanyuxwgaviyonky0lxwq3vq%29%29/Stuff
<sessionState timeout="60" cookieless="true"/>
我可以设置cookieless
属性动态吗?就像是
if(/*condition*/)
{
sessionState .cookieless = "true";
}
else
{
sessionState .cookieless = "UseCookies";
}
Run Code Online (Sandbox Code Playgroud)
这必须是SessionStart
Global.asax中的某个地方
我有以下代码来确定a的年龄 Person
var pList = ctx.Person.Where(x => x.Create > Date);
int Age = pList.Where(x => x.ID == "foo").FirstOrDefault().Age ?? 20;
Run Code Online (Sandbox Code Playgroud)
我选择一个Person
ID,如果它不存在,则默认值为20.
第二行无效,因为Age不能为null但是Person可以.有没有办法让这个工作在一条线上?我尝试过使用DefaultIfEmpty,但似乎没有用.
我有这种扩展方法
public static class Extensions
{
public static void ConsoleWriteLine(this object Value)
{
Console.WriteLine(Value);
}
}
Run Code Online (Sandbox Code Playgroud)
对于整数值我有一点修改
public static void ConsoleWriteLine(this int Value)
{
Console.WriteLine("Integer: " + Value);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:当我写下int x = 1; x.ConsoleWriteLine();
决定在这种情况下采取第二次延期的时候?int
是 object
藏汉