- 数据结构(待补充)
- .NET中的数字(待补充)
- 日期时间
public String store;
public TimeZoneInfo tz;
public TimeSpan open;
public TimeSpan close;
public bool IsOpenNow()
{
return IsOpenAt(DateTime.Now.TimeOfDay);
}
public bool IsOpenAt(TimeSpan time)
{
TimeZoneInfo local = TimeZoneInfo.Local;
TimeSpan offset = TimeZoneInfo.Local.BaseUtcOffset;
// Is the store in the same time zone?
if (tz.Equals(local))
{
return time >= open & time <= close;
}
else
{
TimeSpan delta = TimeSpan.Zero;
TimeSpan storeDelta = TimeSpan.Zero;
// Is it daylight saving time in either time zone?
if (local.IsDaylightSavingTime(DateTime.Now.Date + time))
delta = local.GetAdjustmentRules()[local.GetAdjustmentRules().Length - 1].DaylightDelta;
if (tz.IsDaylightSavingTime(TimeZoneInfo.ConvertTime(DateTime.Now.Date + time, local, tz)))
storeDelta = tz.GetAdjustmentRules()[local.GetAdjustmentRules().Length - 1].DaylightDelta;
TimeSpan comparisonTime = time + (offset - tz.BaseUtcOffset).Negate() + (delta - storeDelta).Negate();
return comparisonTime >= open & comparisonTime <= close;
}
}
- 事件( EventArgs,IObservable 接口)
- 特性(待补充)
- 框架使用准则(省略)
- XML和其序列化(待补充)
- 二进制序列化
MyObject obj = new MyObject();
obj.n1 = 1;
obj.n2 = 24;
obj.str = "Some String";
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, obj);
stream.Close();
//反序列化
IFormatter formatter2 = new BinaryFormatter();
Stream stream2 = new FileStream("MyFile.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
MyObject obj2 = (MyObject)formatter.Deserialize(stream);
stream.Close();
//序列化有4个回调函数
- IO
//Path File Directory 加Info是实例方法
private const string FILE_NAME = "Test.data";
// Use this for initialization
void Start () {
//if (File.Exists(FILE_NAME))
//{
// print(FILE_NAME);
// return;
//}
//using(FileStream fs = new FileStream(FILE_NAME, FileMode.CreateNew))
//{
// using(BinaryWriter w =new BinaryWriter(fs))
// {
// for(int i = 0; i < 11; i++)
// {
// w.Write(i);
// }
// }
//}
//using(FileStream fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read))
//{
// using(BinaryReader r =new BinaryReader(fs))
// {
// for(int i = 0; i < 11; i++)
// {
// print(r.ReadInt32());
// }
// }
//}
打开并追加到日志文件
//using (StreamWriter w = File.AppendText("log.txt"))
//{
// Log("Test1", w);
// Log("Test2", w);
//}
//using (StreamReader r = File.OpenText("log.txt"))
//{
// DumpLog(r);
//}
//向文件写入文件
//string[] lines = { "First line", "Second line", "Third line" };
//string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
bool 是否追加
//using(StreamWriter outputFile =new StreamWriter(Path.Combine(mydocpath, "WriteLines.txt"),false))
//{
// foreach (string line in lines)
// {
// outputFile.WriteLine(line);
// }
//}
//string text = "First line" + Environment.NewLine;
Set a variable to the My Documents path.
//string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
//File.WriteAllText(Path.Combine(mydocpath, "WriteFile.txt"), text);
//string[] lines = { "New line 1", "New line 2" };
//File.AppendAllLines(Path.Combine(mydocpath, "WriteFile.txt"), lines);
//读取文本第一种
//using(StreamReader sr = new StreamReader("Resources/sk.txt"))
//{
// string line = sr.ReadToEnd();
// print(line);
//}
字符串读取字符
//string str = "Some number of characters";
//char[] b = new char[str.Length];
//using (StringReader sr = new StringReader(str))
//{
// // Read 13 characters from the string into the array.
// sr.Read(b, 0, 13);
// Console.WriteLine(b);
// // Read the rest of the string starting at the current string position.
// // Put in the array starting at the 6th array member.
// sr.Read(b, 5, str.Length - 13);
// Console.WriteLine(b);
//}
写入省略
}