This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<People> peoples = new List<People>(); | |
for (int i = 0; i < 10; i++) | |
{ | |
peoples.Add(new People() { Name = i.ToString() }); | |
} | |
foreach (var source in peoples.ToDictionary(people => people.Name)) | |
{ | |
Console.WriteLine(source.Key); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs) | |
{ | |
DirectoryInfo dir = new DirectoryInfo(sourceDirName); | |
DirectoryInfo[] dirs = dir.GetDirectories(); | |
if (!dir.Exists) | |
{ | |
throw new DirectoryNotFoundException( | |
"Source directory does not exist or could not be found: " | |
+ sourceDirName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void deletePath(string path) | |
{ | |
FileSystemInfo fsi; | |
if (File.Exists(path)) | |
{ | |
fsi = new FileInfo(path); | |
} | |
else if (Directory.Exists(path)) | |
{ | |
fsi = new DirectoryInfo(path); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int y = 1; | |
y = y++; | |
Console.WriteLine(y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example example = new Example(); | |
example.ID = 10; | |
example.NameList.Add(new NamePair(){Name = "name1", Value = "value1"}); | |
example.NameList.Add(new NamePair() { Name = "name2", Value = "value2" }); | |
Stream stream = File.Open("EmployeeInfo.osl", FileMode.Create); | |
BinaryFormatter bformatter = new BinaryFormatter(); | |
Console.WriteLine("Writing Employee Information"); | |
bformatter.Serialize(stream, example); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XDocument doc = XDocument.Load("xml.xml"); | |
foreach (var xElement in doc.Descendants("Root")) | |
{ | |
foreach (var s in xElement.Elements()) | |
{ | |
Console.WriteLine(string.Format("{0} : {1}", s.Name, s.Value)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XmlWriterSettings xws = new XmlWriterSettings | |
{ | |
OmitXmlDeclaration = true, | |
Indent = true | |
}; | |
XDocument doc; | |
using (XmlWriter xw = XmlWriter.Create(new StreamWriter(@"D: est.xml"), xws)) | |
{ | |
doc = new XDocument( | |
new XElement("GarbageCanList", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public double CalculateSize() | |
{ | |
if(Directory.Exists(Path)) | |
return new DirectoryInfo(Path).GetFiles(Path, SearchOption.AllDirectories).Aggregate<FileInfo, double>(0, (current, file) => current + file.Length); | |
else if (File.Exists(Path)) | |
return new FileInfo(Path).Length; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System.Windows.SystemParameters.PrimaryScreenWidth | |
System.Windows.SystemParameters.PrimaryScreenHeigth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Extention | |
{ | |
public static bool IsAbstrct(this Type type) | |
{ | |
return type.IsAbstract; | |
} | |
public static bool IsEnumerableType(this Type t) | |
{ | |
return typeof(IEnumerable<string>).IsAssignableFrom(t); |