如何在LINQ中编写这个函数?
public List<TResult> select(List<string> source)
{
List<TResult> result = new List<TResult>();
foreach (var a in source)
{
try { result.Add(TResult.Parse(a)); }
catch { }
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
我想只选择可转换为TResult的项目.TResult.Parse()返回TResult的新实例.
如何制作有效的内存日志,只存储最后100个条目,并可以快速将结果字符串输出到TextBox(每次更新)?
我正在使用文本文件进行实际记录,File.AppendAllText但希望能够查看我的应用程序中的最后一个条目.
我有2个列表,List<Class1>并List<Class2>通过相同的属性Class1.Key和Class2.Key(字符串)进行比较,我想写一个函数,将产生3个列表
List<Class1> 两个列表中都存在的元素List<Class1> 仅存在于第一个列表中的元素List<Class2> 仅存在于第二个列表中的元素有快速的方法吗?
我的网站有PHP命令:
mysql_query("SELECT * FROM users WHERE id=" . $_GET["id"]) or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)
当我输入URL
http://example.com/index.php?id=1;%20UPDATE%20users%20SET%20password=123%20WHERE%20id=1
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE users SET password=abc WHERE id=1' at line 1
但在phpmyamin查询执行成功.这有什么不对?为什么它不在浏览器中执行?
我写了一堂课,想测试它是否运作良好.现在我认为最好的方法是创建新的控制台应用程序引用主项目,然后创建我的类的新实例并搞乱它.这种方法与其他方法不同,它使用关键字(没有类的全名)和调试来实现IntelliSense.
任何人都知道如何以更方便的方式做到这一点,而无需创建新的控制台应用程序?
我想在不创建异常变量的情况下使用其他数据抛出异常.像这样的东西:
throw new Exception() { Data.Add("foo", "bar") };
Run Code Online (Sandbox Code Playgroud)
可能吗?
我有以下代码
public static class StaticClass
{
public static Instance Inst { get; set; }
}
public class Instance
{
public Button Butt { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我需要绑定到Grid.Row附加到Butt按钮的属性。我试过这个:
{Binding Source={x:Static local:StaticClass.Inst.Butt}, Path=(Grid.Row)}
Run Code Online (Sandbox Code Playgroud)
但它不起作用,因为Butt它不是静态属性。通常我使用 x:Static 绑定到静态属性并将其余部分写入 Path,但在这种情况下,Path 包含附加属性。我不知道该怎么做。
我应该将每个班级放在单独的档案中吗?即使那些仅在一个地方使用的短助手类?像这个:
public class IntToVisibilityConverter : GenericValueConverter<int, Visibility>
{
protected override Visibility Convert(int value)
{
return value == 0 ? Visibility.Collapsed : Visibility.Visible;
}
}
Run Code Online (Sandbox Code Playgroud) using System;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Task.Run(Test);
Console.ReadKey();
}
public static async Task Test()
{
var semahore = new SemaphoreSlim(0, 1);
Console.WriteLine("before");
await semahore.WaitAsync();
Console.WriteLine("after");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我创建一个限制为1且当前值为0的信号量.它应该允许1个线程通过,对吧?为什么它不在这个例子中?
为什么这个绑定更新没有?
代码: MainWindow.xaml
<Window x:Class="WpfApplication12.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication12"
Height="350" Width="525">
<StackPanel>
<local:UserControl1 x:Name="usr" />
<TextBlock Text="{Binding ElementName=usr, Path=txt.Text}" />
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
UserControl1.xaml
<UserControl x:Class="WpfApplication12.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBox Text="qwe" x:Name="txt" />
</UserControl>
Run Code Online (Sandbox Code Playgroud) 我试图隐藏错误,但似乎我做错了.在我的托管配置display_errors设置为off,我没有.htaccess文件.我试着写下来的脚本
<?php
echo ord(ini_get("display_errors")) . " ";
die("error");
?>
Run Code Online (Sandbox Code Playgroud)
而且我得到以下输出:
0 error
Run Code Online (Sandbox Code Playgroud)
因此,display_errors设置为关闭,但die()功能仍然在屏幕上显示错误.怎么避免这个?
.net ×9
c# ×9
wpf ×3
data-binding ×2
php ×2
xaml ×2
async-await ×1
asynchronous ×1
coding-style ×1
linq ×1
list ×1
logging ×1
mysql ×1
set ×1
string ×1