随笔分类 - .NET Framework
C# Main函数中调用异步方法的2种实现
摘要:As you discovered, in VS11 the compiler will disallow an async Main method. This was allowed (but never recommended) in VS2010 with the Async CTP. I h
阅读全文
Using Dispatcher
摘要:he following code example shows how you might attempt to update the UI from your task logic. // The Wrong Way to Update a UI Objectpublic void btnGetT
阅读全文
C#修改json文件中的某些值
摘要:using Newtonsoft.Json; JsonSerializer serialiser = new JsonSerializer(); string newContent = string.Empty; using (StreamReader reader = new StreamReader(file.FullName)) ...
阅读全文
字幕文件处理(2) - 字幕文件格式转化
摘要:上一篇文章我们实现了整数与时间格式的互转,常见的字幕文件的格式有WebVTT, SRT, TTML, 有的系统要求我们提供VTT格式, 有的系统只支持TTML格式,我们字幕做完一个拿到的可能是SRT格式, 所以设计到将不同格式的字幕文件进行转换。
阅读全文
字幕文件处理(1) - 时间格式与整数格式互转
摘要:一个字幕文件一般包含两部分内容:时间索引和脚本内容。一般,常见的字幕文件格式有WebVTT, SRT和TTML。 编辑字幕文件就是对每一段字幕的时间索引或脚本内容进行编辑。也包括对字幕文件的格式进行转换,参考字幕文件处理(2) - 字幕文件格式转化。
阅读全文
将对象序列化,反序列化到XML
摘要:using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Serialization; using Windows.Storage; namespace ...
阅读全文
Newtonsoft.Json 处理多态类型的反序列化
摘要:Newtonsoft.Json的序列化和反序列化很成熟也很好用, 最近在处理多态类型的反序列化中遇到了问题, 反序列化后只能到基类,而得不到也不能转换到子类。从网上查询了一番后,需要写一个创建类型的Converter, 下面我们一步一步来: 1. 首先说明类型的定义, 为了做这个实验,我定义了一个基
阅读全文
创建XML文档结构
摘要:static void CreateXML(string outputPath) { XmlDocument _xmlDoc = new XmlDocument(); string _xmlNode = @""; ...
阅读全文
枚举和字符串转换
摘要:public static String convertToString(this Enum eff){ return Enum.GetName(eff.GetType(), eff);}public static EnumType converToEnum(this String enumValue) { return (EnumType) Enum.Parse(typeof(EnumType), enumValue);}post from : http://stackoverflow.com/questions/483794/convert-enum-to-string
阅读全文
String.Format 全汇总
摘要:C#格式化数值结果表字符说明示例输出C货币string.Format("{0:C3}", 2)$2.000D十进制string.Format("{0:D3}", 2)002E科学计数法1.20E+0011.20E+001G常规string.Format("{0:G}", 2)2N用分号隔开的数字string.Format("{0:N}", 250000)250,000.00X十六进制string.Format("{0:X000}", 12)Cstring.Format("{0:000.
阅读全文
Send Mail using C# code
摘要:using System.Net.Mail; public class MailHelp { public static void Send(string subject, string body) { MailMessage message = new MailMessage(); SmtpClient client = new SmtpClient(); client.Port = 25; client.Host = "smtphost.mycompany.com...
阅读全文
重载 Sort, ==, !=
摘要:class Items:IComparable { public string Item { get; set; } public string File { get; set; } public string IsScored { get; set; } public string Weight { get; set; } public int CompareTo(object obj) { if (obj is Items) { ...
阅读全文
XML节点访问与更新
摘要:1. XML节点访问与更新.2. DataGridView, 把 string[] bind到DataGridView.3. 通过封装器, 做成List<StringValue>.usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Xml;usingSystem.IO;names
阅读全文
connection string for Excel/Access 2010
摘要:Excel 2010 连接字符串case1:ConnectionString=string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource={0};ExtendedProperties='Excel8.0;HDR=Yes;IMEX=1'",ExcelPath);break;case2:ConnectionString=string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource={0};ExtendedProperties='
阅读全文
读书笔记: 泛型 - CLR via C#
摘要:为什么泛型?面向对象的语言好处是使得程序员可以很方便地重用代码, 在面向对象中程序员可以写一个子类去继承自一个父类,写不同的程序能够重用以前的代码, 会减少很多代码的工作量。但是算法能不能重用呢? 答案是肯定的, CLR提供了一个算法重用的机制, 就是泛型。算法重用的例子, 参考List<T>类型, 在System.Collections.Generic中定义。泛型类型和继承我们使用两段代码来说明:Internal sealed class Node<T>{Public T m_data;Public Node<T> m_next;Public Node(T
阅读全文
timer.elapsed里边调用button.click事件
摘要:在timer.elapsed里边调用button.click事件 悬赏分:5 - 解决时间:2010-8-10 11:19 提问者: 7788wangzi - 二级最佳答案
阅读全文
从文本文件读取信息
摘要:你若想要程序获取用户信息,比如:名字, 登录名. 而这些信息有不是固定不变的, 你可以从文本文件中读取这些信息, 怎样从文本文件中读取信息, 用到了.net的System.IO命名空间, 具体如下:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--s...
阅读全文
通过IP地址获得主机名
摘要:如果你遇到这样的场景, 你知道远程机器的ip地址, 想要通过ip地址来获得主机名。可以使用.net的System.Net命名空间, 这里边有一个类是IPHostEntry, 使用方式如下:[代码]若是通过主机名获得IP地址也是使用此类.[代码]
阅读全文
.NET 4.0 数组比较
摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1///<summary>2///NewFeaturein.NET4.03///Comparetwoarray4///usingIStructuralEquatable5///usingE...
阅读全文
DIY播放器(使用MediaPlayer)
摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1///themostimportantthingistoreferencetheMediaPlayerinCOMTab2///qixue3usingSystem;4usingSystem.Colle...
阅读全文
浙公网安备 33010602011771号