string userProfilePath = Environment.ExpandEnvironmentVariables("%USERPROFILE%");
string directoryToDelete = Path.Combine(userProfilePath, "AppData", "Local", "MyApplicationFolder");
DirectoryInfo di = new DirectoryInfo(directoryToDelete);
di.GetFiles().ToList().ForEach(f => f.Delete());
di.GetDirectories().ToList().ForEach(d => d.Delete());
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
class Program
{
static void Main()
{
var lpixels = new LPixels();
lpixels.ListPixels.Add(new Pixels(1, 1, "test11"));
lpixels.ListPixels.Add(new Pixels(1, 2, "test12"));
lpixels.ListPixels.Add(new Pixels(2, 1, "test21"));
var find = lpixels.ListPixels.First(x => x.x == 1 && x.y == 2);
Console.WriteLine(find.text);
}
}
public class LPixels
{
public List<Pixels> ListPixels = new List<Pixels>();
}
public class Pixels
{
public Pixels (int x, int y, string text)
{
this.x = x;
this.y = y;
this.text = text;
}
public int x;
public int y;
public string text;
}
private void FoldersToFile()
{
var folder = @"C:\Temp";
var fileResult = @"X:\Temp\result.txt";
TextWriter tw = new StreamWriter(fileResult, false, Encoding.Default);
tw.WriteLine(folder);
Directory.GetDirectories(folder, "*", SearchOption.AllDirectories)
.ToList().ForEach(dir =>
{
tw.WriteLine(dir);
Directory.GetFiles(dir).ToList().ForEach(file => tw.WriteLine(file));
});
tw.Close();
}
private void ReadFile()
{
var fileResult = @"X:\Temp\result.txt";
var content = File.ReadAllLines(fileResult).ToList();
foreach (var element in content)
{
if (treeView1.Nodes.Count >0)
{
var x = SearchNode(Directory.GetParent(element).ToString(), treeView1.Nodes[0]);
x?.Nodes.Add(element);
}
else treeView1.Nodes.Add(element);
}
treeView1.ExpandAll();
}
string testJson = "{'name':'Test','response':1}";
static void Main(string[] args)
{
string testJson = "{ \"channels\" : [ { \"guid\" : \"sHyGfRs\", \"name\" : \"Name 1\", \"rights\" : \"783\", \"codec\" : \"h264\", \"have_ptz\" : \"0\", } ] }";
var result = JsonConvert.DeserializeObject<RootObject>(testJson);
Console.WriteLine($"Name: {result.channels.FirstOrDefault().guid}");
}
public class Channel
{
public string guid { get; set; }
public string name { get; set; }
public string rights { get; set; }
public string codec { get; set; }
public string have_ptz { get; set; }
}
public class RootObject
{
public List<Channel> channels { 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}");
}
double x1 = 0.0010000456;
double x2 = 0.001;
Console.WriteLine(x1 == x2);
//Способ 1. Округляем числа до 4 знаков и сравниваем
Console.WriteLine(Math.Round(x1, 4) == Math.Round(x2, 4));
//Способ 2. Через разность
Console.WriteLine(Math.Abs(x1 - x2) < 0.0001);
//Способ 3. Через string и convert. !!! ШУТКА !!! В РЕАЛЬНОМ КОДЕ НЕ ИСПОЛЬЗОВАТЬ
string strx1 = x1.ToString().Substring(0, 5);
string strx2 = x2.ToString().Substring(0, 5);
Console.WriteLine(strx1 == strx2);