.NET相关知识(二)

  1. 数据结构(待补充)
  2. .NET中的数字(待补充)
  3. 日期时间
    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;
        }
    }
  1. 事件( EventArgs,IObservable 接口)
  2. 特性(待补充)
  3. 框架使用准则(省略)
  4. XML和其序列化(待补充)
  5. 二进制序列化
        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个回调函数
  1. 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);
        //}
        写入省略
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值