var lines = new List<string>();
lines.AddRange(textBox1.Lines);
DateTimeOffset.Now.ToUnixTimeSeconds()
DateTime foo = DateTime.Now;
long unixTime = ((DateTimeOffset)foo).ToUnixTimeSeconds();
var startDate = DateTime.Now.AddYears(-100);
var endDate = DateTime.Now;
Random rnd = new Random();
for (int i = 0; i < 10; i++)
{
var randomYear = rnd.Next(startDate.Year, endDate.Year);
var randomMonth = rnd.Next(1, 12);
var randomDay = rnd.Next(1, DateTime.DaysInMonth(randomYear, randomMonth));
if (randomYear == startDate.Year)
{
randomMonth = rnd.Next(startDate.Month, 12);
if (randomMonth == startDate.Month)
randomDay = rnd.Next(startDate.Day, DateTime.DaysInMonth(randomYear, randomMonth));
}
if (randomYear == endDate.Year)
{
randomMonth = rnd.Next(1, endDate.Month);
if (randomMonth == endDate.Month)
randomDay = rnd.Next(1, endDate.Day);
}
var randomDate = new DateTime(randomYear, randomMonth, randomDay);
Console.WriteLine($"Random date: Year {randomDate.Year}, month {randomDate.Month}, day {randomDate.Day}");
}
public Form1()
{
InitializeComponent();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
ulong appID = 1234567;
var email = "example@mail.ru";
var pass = "Pa$$w0rd";
var scope = Settings.Messages;
var vk = new VkApi();
vk.Authorize(new ApiAuthParams
{
ApplicationId = appID, Login = email, Password = pass, Settings = scope
});
var users = vk.Messages.GetChatUsers(29);
foreach (var user in users)
{
Console.WriteLine($"UserId: {user}");
}
string file = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Otherfile";
string file = Environment.ExpandEnvironmentVariables(@"%LOCALAPPDATA%\Otherfile");
string appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string file = Path.Combine(appData, "Otherfile");
string sourceString = "Есть текст нужно чтобы. через каждые 300 символов искал запятую, точку, пробел и т.д (Искал не после 300 символов а именно в этом отрезке 0 - 300 или например 300 - 600) и после этого символа(запятой, точки, пробела и т.д.) делал перенос строки и так далее. Я хочу вывести это через Label, я знаю что есть вариант с Textbox но он мне не подходит.";
int length = 50;
char[] charsForEOL = { '.', ',', ' ' };
string resultString = "";
label1.Text = sourceString;
do
{
for (int i = length; i >= 1; i--)
{
if (charsForEOL.Contains(sourceString[i]))
{
resultString += sourceString.Substring(0, i) + "\n";
sourceString = sourceString.Substring(i + 1);
break;
}
if(i == 1)
{
resultString += sourceString.Substring(0, length) + "\n";
sourceString = sourceString.Substring(length + 1);
}
}
} while (sourceString.Length > length);
resultString += sourceString;
label2.Text = resultString;
const string filename = "file.xml";
private void Form1_Load(object sender, EventArgs e)
{
if (!File.Exists(filename)) return;
var doc = XDocument.Load(filename);
foreach (Control control in this.Controls)
{
if (control is TextBox)
{
var element = doc.Root.Elements().FirstOrDefault(x => x.Name == control.Name);
control.Text = (element != null) ? element.Value : "";
}
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
var element = new XElement("Settings");
foreach (Control control in this.Controls)
{
if (control is TextBox)
{
element.Add(new XElement(control.Name, control.Text));
}
}
XDocument doc = new XDocument(element);
doc.Save(filename);
}
static void Main()
{
int number_user1 = 0;
while (true)
{
Console.Write("Player 1 write number from 1 to 5: ");
string inputChar = Console.ReadKey().KeyChar.ToString();
if(int.TryParse(inputChar, out number_user1) && number_user1 <= 5 && number_user1 > 0)
{
break;
}
else
{
Console.WriteLine($"\nEnter only NUMBERS from 1 to 5 (you input {inputChar})");
}
}
Console.WriteLine($"\nYou input {number_user1}");
Console.Write("Press any key to close"); Console.ReadKey();
}
string testJson = "{'name':'Test','response':1}";
static void Main(string[] args)
{
string testJson = "{'name':'Test','response':1}";
var result = JsonConvert.DeserializeObject<MyClass>(testJson);
Console.WriteLine($"Name: {result.Name}, Response: {result.Response}");
}
class MyClass
{
public string Name { get; set; }
public int Response { get; set; }
}
static void Main(string[] args)
{
string testJson = "{'name':'Test','response':1}";
dynamic resultDynamic = JObject.Parse(testJson);
Console.WriteLine($"Name: {resultDynamic.name}, Response: {resultDynamic.response}");
}
string dir = @"X:\Dir1\Dir2\Dir3\Dir4\Dir5\Dir6";
//1
Console.WriteLine(Directory.GetParent(
Directory.GetParent(dir).FullName).FullName);
//2
DirectoryInfo dir2 = new DirectoryInfo(dir);
Console.WriteLine(dir2.Parent.Parent.FullName);
Stack before;
public Form1()
{
InitializeComponent();
before = new Stack();
}
private void buttonBackspace_Click(object sender, EventArgs e)
{
if (before.Count > 0){
maskedTextBox1.Text = before.Pop().ToString(); }
}
private void maskedTextBox1_KeyUp(object sender, KeyEventArgs e)
{
before.Push(maskedTextBox1.Text);
}