class A {}
class B : A {}
class C : A {}
ICollection<A> myCollection;
var myresults = myCollection.Where(item => item.GetType() is C);
Run Code Online (Sandbox Code Playgroud)
鉴于上面的层次结构,谓词有效地做了什么.
如何构造where谓词以从集合中返回C类型的所有项?
我们有这个模块,用户可以注册,他们需要确认他们的电子邮件地址.
目前我使用.NET发送电子邮件.所以在添加记录后,我现在将调用我的电子邮件方法.但我注意到有时候电子邮件功能确实收到超时错误,因为我捕获所有异常,这个错误会呈现给用户.
我想要的是在后台发送电子邮件.如果有任何邮件连接超时,电子邮件方法将只重试发送电子邮件大概一两分钟.我正在考虑使用SQL邮件来实现这一目标.但我不确定它是否是最好的解决方案.
我试图看看是否有一种不同的/更好的方法来解析我拥有的字符串.
字符串是"#def xyz [timer = 50,fill = 10]".从这个字符串我试图检索计时器和填充值.
我目前的代码是:
string def = "#def xyz[timer=50, fill=10]";
string _timer = def.Remove(def.IndexOf(","));
_timer = _timer.Remove(0, _timer.IndexOf("=", _timer.IndexOf("timer")) + 1);
string _fill = def.Remove(def.IndexOf("]"));
_fill = _fill.Remove(0, _fill.IndexOf("=", _fill.IndexOf("fill")) + 1);
int timer = Int32.Parse(_timer);
int fill = Int32.Parse(_fill);
Run Code Online (Sandbox Code Playgroud)
有什么建议?
提前致谢!
是否可以解决以下问题而不使用C#循环(foreach; for; while; etc)但只使用C#Linq或lambda表达式?
问题:给定一个Task对象列表和一个已删除的TaskIds列表.我想该列表只与那些元素更新不去掉TaskID的名单,剩下的任务元素重新排序了.
(1*) Given a list of Task objects:
TaskId Group Name Order
281 1 "abc" 1
726 1 "dre" 2 // note: will be removed
9891 1 "euf" 3 // note: will be removed
87 1 "wop" 4
932 1 "hjd" 5
102 2 "fhl" 1 // note: will be removed
44 2 "bgg" 2
30 2 "qds" 3
293 2 "djf" 4 // note: will be removed
389 2 "hkd" …Run Code Online (Sandbox Code Playgroud) 注意:这是我第一次使用WPF.
我试图在右下角对齐某个控件,现在就说一个按钮.但是当我调试我的应用程序时,它错过了8个像素的底部和右侧.我会附上2张照片,告诉你会发生什么.
如何保持按钮到位?
我的XAML代码:
<Window x:Class="Plugin_Manager.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Plugin Manager" Height="350" Width="525" Loaded="Window_Loaded_1">
<Grid x:Name="GridMain">
<Button Content="Refresh" Margin="432,288,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="75"/>
<ListView HorizontalAlignment="Left" Height="273" Margin="10,10,0,0" VerticalAlignment="Top" Width="497">
<ListView.View>
<GridView>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
</Grid>
Run Code Online (Sandbox Code Playgroud)

我正在尝试向使用BASIC身份验证和https保护的服务发送HTTP GET请求.如果我使用RESTClient Firefox插件这样做没有问题.我正在定义basic-header并将GET发送到url,我得到了答案(json中的数据).
现在我正在使用C#中的Windows应用商店应用程序来使用该服务.我在清单中启用了所有必需的功能,并编写了以下方法:
private async void HttpRequest()
{
string basic = "Basic ...........";
Uri testuri = new Uri(@"https://...Servlet");
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", basic);
Task<HttpResponseMessage> response = client.GetAsync(testuri);
var text = await response;
var message = text.RequestMessage;
}
Run Code Online (Sandbox Code Playgroud)
我尝试了许多不同的可能性,例如获取响应字符串但是所有内容都会导致服务器发出401状态代码答案.
我查看了许多类似的问题,我对通信的理解如下:客户端请求 - >服务器响应401 - >客户端发送授权标头 - >服务器响应200(确定)
我不明白为什么我得到401"未授权"状态代码,虽然我在开始时发送授权标题.如果有人知道如何在RESTClient中处理它,那将会很有趣.
BASIC标题是完全正确的我将它与RESTClient中的标题进行比较.
如果有人可以帮助我,这将是很好的.
在此先感谢您的亲切问候,Max
c# basic-authentication http-status-code-401 dotnet-httpclient
我正在尝试使用C#片段中的用户输入实现欧几里德算法,作为我学习该语言过程的一部分.MVS告诉我if和elif语句以及这些语句的结束括号都有错误.现在,来自pythonic背景这对我来说似乎很自然,所以请帮助我找出可能的错误.非常感谢帮助.
码:
namespace EuclideanAlgorithm
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two numbers to calculate their GCD");
int input1 = Convert.ToInt32(Console.ReadLine());
int input2 = Convert.ToInt32(Console.ReadLine());
int remainder;
int a;
int b;
if (input1 == input2);
{
Console.Write("The GCD of", input1, "and", input2, "is", input1);
Console.ReadLine();
}
else if (input1 > input2);
{
a = input1;
b = input2;
while (remainder != 0);
{
remainder = a % b;
a = b;
b = remainder;
}
Console.Write("The GCD …Run Code Online (Sandbox Code Playgroud) public static implicit operator byte(BytesType o) { return ConvertTo<byte>(o); }
Run Code Online (Sandbox Code Playgroud)
以上是从类型的对象o隐式转换BytesType为byte.
但是以下是做什么的
public static implicit operator byte?(BytesType o) { return ConvertTo<byte>(o); }
Run Code Online (Sandbox Code Playgroud)
特别是条件运算符.条件运算符表示什么?
提前致谢.
我为System.Type创建了一个扩展方法,我想对该方法进行单元测试.这可能吗?谢谢!
public static bool GetFoo(this Type self)
{
if (self == null)
{
throw new ArgumentNullException("this")
}
...
}
Run Code Online (Sandbox Code Playgroud) 我是sql的新手.我在数据库中添加了2个新表.第一个主键是另一个的外键.键的类型是整数.现在我想在代码中生成密钥并将其分配给新数据,以便表的不同行之间的关联是正确的.如何确保密钥的唯一性,并从数据库中获取最新密钥,以便在保存时不会出现错误.
如果我使用了guid,那么我会为主键分配一个新的guid,然后将其分配给另一个表中的外键.还有多个客户端和一个保存数据的服务器.
要插入到两个表中的数据在c#代码中确定,而不是从插入主表中的行派生的.即使在db中获取id,那么行之间的关系也应该以某种形式存储在代码中,因为之后它就会丢失.