<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Libs" />
</assemblyBinding>
</runtime>
</configuration>
mkdir $(TargetDir)Libs
move $(TargetDir)*.dll $(TargetDir)\Libs\
Советы и примеры задач, которые помогут вам в освоении нового языка программирования
Сети и протоколы
var updates = (JContainer)JObject.Parse(json)["updates"];
dynamic results = updates.Descendants()
.OfType<JObject>()
.Where(x => x["source_text"] != null).FirstOrDefault();
Console.WriteLine(results.source_text);
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
var form2 = new Form2();
if (form2.ShowDialog() == DialogResult.OK)
{
timer1.Enabled = true;
}
}
public static DateTime GetNetworkTime()
{
const string ntpServer = "time.windows.com";
var ntpData = new byte[48];
ntpData[0] = 0x1B;
var addresses = Dns.GetHostEntry(ntpServer).AddressList;
var ipEndPoint = new IPEndPoint(addresses[0], 123);
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
{
socket.Connect(ipEndPoint);
socket.Send(ntpData);
socket.Receive(ntpData);
socket.Close();
}
var intPart = (ulong)ntpData[40] << 24 | (ulong)ntpData[41] << 16 | (ulong)ntpData[42] << 8 | ntpData[43];
var fractPart = (ulong)ntpData[44] << 24 | (ulong)ntpData[45] << 16 | (ulong)ntpData[46] << 8 | ntpData[47];
var milliseconds = (intPart * 1000) + ((fractPart * 1000) / 0x100000000L);
var networkDateTime = (new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddMilliseconds((long)milliseconds);
return networkDateTime.ToLocalTime();
}
var persons = new[]
{
new { Name = "Юрий Васильевич Кондратюк", BirthDate = new DateTime(1897, 06, 9) },
new { Name = "Михаил Фёдорович Решетнёв", BirthDate = new DateTime(1924, 11, 10) },
new { Name = "Михаил Тимофеевич Калашников", BirthDate = new DateTime(1919, 11, 10) },
new { Name = "Сергей Павлович Королёв", BirthDate = new DateTime(1907, 1, 12) },
new { Name = "Михаил Васильевич Ломоносов", BirthDate = new DateTime(1711, 11, 8) }
};
int[] arr = persons.Where(n => n.Name.Contains("Михаил"))
.GroupBy(day => day.BirthDate.Day)
.Select(count => count.Count())
.ToArray();
Array.ForEach(arr, Console.WriteLine);
var sqlConnection = new SqlConnection("Data Source=localhost;" +
"Initial Catalog=tosterTest;" +
"Integrated Security=SSPI;");
sqlConnection.Open();
var command = new SqlCommand("SELECT * FROM [Admin]", sqlConnection);
var sqlReader = await command.ExecuteReaderAsync();
await sqlReader.ReadAsync();
if ( textBox1.Text == sqlReader["login"].ToString()
&& textBox2.Text == sqlReader["pass"].ToString())
{
MessageBox.Show("Всё верно!");
}
else
MessageBox.Show("Неправильный логин или пароль");
Group.Children.Add(new ModelVisual3D() { Content = new AmbientLight(Colors.White) });
Советы и примеры задач, которые помогут вам в освоении нового языка программирования
но мне не нравится код, слишком он кажется сложен для чтения и сам потом забуду куда и что
private static void Main()
{
var test = "!send testUser testCommand";
var parsed = ParseMessage(test);
var argsMessage = parsed.Args.Split(' ');
switch (parsed.Command)
{
case "send":
Command.Send(friend: argsMessage[0], message: argsMessage[1]);
break;
case "buy":
Command.Buy(nameToBuy: argsMessage[0]);
break;
default:
Console.WriteLine("Unknow command");
break;
}
}
private static (string Command, string Args) ParseMessage(string message)
{
var map = new[] {
new { Value = "!buy", Result = ("buy", message.Replace("!buy ", "")) },
new { Value = "!send", Result = ("send", message.Replace("!send ", "")) }
};
var value = map.Where(e => message.StartsWith(e.Value)
? message.StartsWith(e.Value) : message == e.Value)
.Select(e => e.Result)
.FirstOrDefault();
if(string.IsNullOrEmpty(value.Item1)) value = ("Unknow command", "");
return value;
}
private static class Command
{
public static void Send(string friend, string message)
{
Console.WriteLine($"Fried: {friend}, Message {message}");
}
public static void Buy(string nameToBuy)
{
Console.WriteLine($"nameToBuy {nameToBuy}");
}
}