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)中最好.
  • 相关阅读:
    CSS3(4)---动画(animation)
    MDT 2010驱动管理新方法。
    windows 2012 试用180天
    Mac地址绑定的wifi
    用于主题检测的临时日志(b2d5c7b3-e3f6-4b0f-bfa4-a08e923eda9b
    samba4.1.9安装
    samba权限之easy举例说明--原创
    NFS性能优化
    工作组环境下管理windows.
    管理windows防火墙
  • 原文地址:https://www.cnblogs.com/oisiv/p/407256.html
Copyright © 2011-2022 走看看