zoukankan      html  css  js  c++  java
  • c#中幾個常用代碼

    文件操作

    string path = @"e:\MyTest.txt";
     DateTime dt 
    = DateTime.Now;
                    
    if (!File.Exists(path)) 
                    
    {
                        
    // Create a file to write to.
                        using (StreamWriter sw = File.CreateText(path)) 
                        
    {
                            sw.WriteLine(
    "time"+dt.ToString());
                            sw.WriteLine(hashtable.Count.ToString());
                        }
        
                    }

                    
    else
                    
    {
                        
    using (StreamWriter sw = File.AppendText(path)) 
                        
    {
                            sw.WriteLine(
    "time"+dt.ToString());
                            sw.WriteLine(hashtable.Count.ToString());
                        }

                    }


    web應用中的Cache操作
    Cache cache = System.Web.HttpContext.Current.Cache;
    string obj=null;
    cache.Insert(
    "cache1",obj,null,DateTime.Now.AddHours(1),TimeSpan.Zero,CacheItemPriority.AboveNormal,null);
    當然對於簡單的字符串,使用以下方式即可
    Application["Title"= "Test Sample";

    cache操作可以放在任何地方,當然放在Global.asax的Application_Start(Object sender, EventArgs e)中最好.
  • 相关阅读:
    J Identical Trees(求俩个树转化所需的最小代价,hash判同构,费用流求转移代价)
    I Tournament(俩人一组,构造最少排队总时间)
    D
    purfer序列(有关度数与生成树个数情况)
    博客园自定义样式
    莫比乌斯知识点整理
    随笔日记
    牛客小白月赛16
    Codeforces Round #555 (Div. 3)
    Codeforces Round #553 (Div. 2)
  • 原文地址:https://www.cnblogs.com/oisiv/p/407256.html
Copyright © 2011-2022 走看看