我有一个通常包含字段,属性的类。我要实现的不是此:
class Example
{
public string Field = "EN";
public string Name { get; set; }
public int? Age { get; set; }
public List<string> A_State_of_String { get; set; }
}
public static void Test()
{
var c1 = new Example
{
Name = "Philip",
Age = null,
A_State_of_String = new List<string>
{
"Some Strings"
}
};
var c2 = new Example();
//Instead of doing that
c2.Name = string.IsNullOrEmpty(c1.Name) ? "" : c1.Name;
c2.Age = c1.Age ?? 0;
c2.A_State_of_String = …Run Code Online (Sandbox Code Playgroud) 好吧,我有一个Form,它接收Employee的级别,并根据他的级别启用一些选项Checkboxes.然而,我面临的问题是,对于我的应用程序的逻辑,每个选项都有特定的级别范围,所以我创建了一个丑陋的IF范围检查语句,我相信有更好的方法来实现.
代码:
if (level >= 1 && level < 3) {
_items[0].Enabled = true;
_items[1].Enabled = false;
_items[2].Enabled = false;
_items[3].Enabled = false;
_items[4].Enabled = false;
_items[5].Enabled = false;
_items[6].Enabled = false;
_items[7].Enabled = false;
}
else if (level >= 3 && level < 5) {
_items[0].Enabled = true;
_items[1].Enabled = true;
_items[2].Enabled = false;
_items[3].Enabled = false;
_items[4].Enabled = false;
_items[5].Enabled = false;
_items[6].Enabled = false;
_items[7].Enabled = false;
}
else if (level >= …Run Code Online (Sandbox Code Playgroud) 我正在创建基于异步套接字的客户端服务器通信,我的客户端会将用户名和密码发送到服务器,然后服务器将重播该帐户是否有效,所以我想确保这一步骤,所以没有人可以记录对话并保持发送给我的客户端以实现非法进入秘密数据
[问题{简化}]如何安全地验证客户端到服务器......?
[注意]我知道SSL,但我不能支付证书,所以我需要一个免费的替代品,以提供我的客户端和服务器之间的安全通信.
好吧,我正在创建一个程序,我需要一个单独的窗口来显示日志.
我设法使用另一种形式
form1.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
但不幸的是,这会将焦点转移到显示的形式,并且用户无法点击之前的表单,直到他关闭它.
问题:我如何同时使用2个单独的表格(一个用于主ui,一个用于记录器).
好吧,我想解析那个日期
5/10/2013 002704
var stt = "5/10/2013 002704";
result = DateTime.ParseExact(stt, "dd-MM-yyyy HHmmss", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
但我得到了这个例外
字符串未被识别为有效的DateTime.
但是!,此代码仅用于解析时间*without date*
var stt = "002704";
result = DateTime.ParseExact(stt, "HHmmss", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
好吧,我希望有人帮助我解决这个问题,并提前感谢...
提示:这也是失败的
var stt = "5/10/2013 002704";
result = DateTime.ParseExact(stt, "dd/MM/yyyy HHmmss", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
好吧它有效!感谢每一个人帮助我,为他的\非常好的帮助,我非常感谢.此外,我将在下次考虑XY问题:D.
为了使我的代码更有条理,我决定使用流畅的接口; 然而,通过阅读可用的教程,我找到了很多方法来实现这种流畅性,其中我找到了一个主题,他说创建Fluent Interface我们应该使用Interfaces,但他没有提供任何好的细节来实现它.
以下是我如何实现Fluent API
public class Person
{
public string Name { get; private set; }
public int Age { get; private set; }
public static Person CreateNew()
{
return new Person();
}
public Person WithName(string name)
{
Name = name;
return this;
}
public Person WithAge(int age)
{
Age = age;
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
Person person = Person.CreateNew().WithName("John").WithAge(21);
Run Code Online (Sandbox Code Playgroud)
但是,我如何让Interfaces以更有效的方式创建Fluent API?
好吧,对我来说,数据包碎片是如何发生的似乎很模棱两可,因为它在我的本地测试中从未发生过,而且在通知我的应用程序我实际上收到了一些信息之前,我不知道该怎么做才能处理碎片化的数据包。
这是我从连接的客户端套接字接收的方式
var asynchronousState = (AsynchronousState) ar.AsyncState; // AsynchronousState is an entity that Holds each connected socket's Buffer, IPEndPoint and so on...
try {
Socket socket = asynchronousState.Socket;
int length = socket.EndReceive(ar);
if (0 != length) {
if (null != ClientReceive) {
var bytes = new byte[length];
Array.Copy(asynchronousState.Buffer, bytes, length);
ClientReceive(asynchronousState, bytes);
Array.Clear(asynchronousState.Buffer, 0, asynchronousState.Buffer.Length);
}
if (socket.Connected) {
socket.BeginReceive(asynchronousState.Buffer, 0, asynchronousState.Buffer.Length, SocketFlags.None, HandleAsyncReceive, asynchronousState);
return;
}
}
DisposeSocket(asynchronousState);
}
catch (SocketException exception) {
if (exception.SocketErrorCode != SocketError.Disconnecting &&
exception.SocketErrorCode …Run Code Online (Sandbox Code Playgroud)