<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>张文杰的博客 &#187; C#</title>
	<atom:link href="http://zhangwenjie.net/archives/tag/c/feed" rel="self" type="application/rss+xml" />
	<link>http://zhangwenjie.net</link>
	<description>技术、生活博客</description>
	<lastBuildDate>Mon, 24 Oct 2011 14:23:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>.NET Framework 4.0中的按需构造:Lazy</title>
		<link>http://zhangwenjie.net/archives/263</link>
		<comments>http://zhangwenjie.net/archives/263#comments</comments>
		<pubDate>Sat, 30 Jan 2010 15:09:03 +0000</pubDate>
		<dc:creator>zhangwenjie</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://zhangwenjie.net/?p=263</guid>
		<description><![CDATA[假设您正在编写一个应用程序，在某些情况下需要使用一个特定对象。此外，假设您需要的对象的创建和使用是非常昂贵的,你不想每次您的应用程序运行时都创建它，只在你需要它的时候才创建它...]]></description>
			<content:encoded><![CDATA[<p>　　假设您正在编写一个应用程序，在某些情况下需要使用一个特定对象。此外，假设您需要的对象的创建和使用是非常昂贵的,你不想每次您的应用程序运行时都创建它，只在你需要它的时候才创建它。</p>
<p>　　当然你可以自己管理这一切，但 Lazy&lt;T&gt;将使这个任务变得容易。你只需要在那个”昂贵”的对象上创建一个 lazy包装器：</p>
<pre lang="C#">Lazy&lt;ExpensiveResource&gt; ownedResource = new Lazy&lt;ExpensiveResource&gt;();</pre>
<p>　　然后你可以简单引用 ‘ownedResource.Value’来获取那个”昂贵”的对象。当你第一次访问ownedResource.Value时,这个”昂贵”的资源才会被分配，而不是以前就分配。</p>
<p>　　Lazy&lt;T&gt;同时还有一个boolean属性，叫IsValueCreated，你可以检查这个属性来查看值是否已经创建。</p>
<p>　　<strong>支持没有默认构造函数的类型</strong></p>
<p><strong>　　</strong>Lazy&lt;T&gt; 不会强制new()约束。你可以在支持不同构造函数，甚至工厂方法实例化的类型上使用Lazy&lt;T&gt;。第二个构造函数指定一个返回新”昂贵”资源的泛型方法：Func&lt;T&gt;：</p>
<pre lang="C#">Lazy ownedResource = new Lazy(    () =&gt; new ExpensiveResource("filename.data"));</pre>
<p>　　你可以使用这个第二个构造函数来更好的控制使用什么样的代码来创建这个”昂贵”的资源。我在这使用了一个不同的构造函数，但你可以使用工厂方法、IOC容器、或其它方法。</p>
<p>　　<strong>我们生活在多核的世界</strong></p>
<p><strong>　　 </strong>Lazy&lt;T&gt;另有两个其它构造函数：</p>
<pre lang="C#">public Lazy(bool isThreadSafe);
public Lazy(Func&lt;T&gt; valueFactory, bool isThreadSafe);</pre>
<p>　　这两个构造函数指示出程序运行在多核的环境中。”昂贵”对象延迟(lazy)创建必须进行同步。（毕竟是”昂贵”对象，你不会需要两个这种对象）。</p>
<p>　　这是一个简单的类型，但正是这些类型你将一次又一次使用他们。</p>
<p>　　首发张文杰的博客:http://zhangwenjie.net （转载请保留，谢谢）。本文地址： http://zhangwenjie.net/archives/263.html <a href="options-permalink.php" target="_blank"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://zhangwenjie.net/archives/263/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在C#中使用GnuPG加密文件</title>
		<link>http://zhangwenjie.net/archives/193</link>
		<comments>http://zhangwenjie.net/archives/193#comments</comments>
		<pubDate>Mon, 04 Jan 2010 13:39:34 +0000</pubDate>
		<dc:creator>zhangwenjie</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[GnuPG]]></category>
		<category><![CDATA[GPG]]></category>
		<category><![CDATA[PGP]]></category>
		<category><![CDATA[加密]]></category>
		<category><![CDATA[签名]]></category>

		<guid isPermaLink="false">http://zhangwenjie.net/?p=193</guid>
		<description><![CDATA[　　PGP可以解释为Pretty Good Privacy（汉语翻译：相当好的隐私），是PGP公司的加密和／或签名工具套件，使用了有商业版权的IDEA算法并集成了有商业版权的PGPdisk工具，有别于开源的GPG（GnuPG）。PGP的主要开发者为菲利普·齐默曼（Philip R. Zimmermann）。齐默曼在志愿者的帮助下，突破政府的禁止，于1991年将PGP在因特网上免费发布。 　　PGP是一个桌面工具，在程序中使用相当不便。好在我们可以使用开源的GPG（GnuPG）在程序代码中写成文件加密。详见如下代码: using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Diagnostics; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { //EncryptPGP(); Stopwatch sw = new Stopwatch(); sw.Start(); DecryptPGP(); sw.Stop(); Console.WriteLine(sw.Elapsed); Console.WriteLine("OK"); Console.Read(); } public static void EncryptPGP() { ProcessStartInfo pInfo = new ProcessStartInfo(); pInfo.FileName = @"E:\Test\GnuPGDotNet\GnuPG\gpg.exe"; pInfo.Arguments = [...]]]></description>
			<content:encoded><![CDATA[<p>　　<strong>PGP</strong>可以解释为<strong>P</strong>retty <strong>G</strong>ood <strong>P</strong>rivacy（汉语翻译：相当好的隐私），是PGP公司的加密和／或签名工具套件，使用了有商业版权的<a title="IDEA" href="/zh-cn/IDEA">IDEA</a><a title="算法" href="/zh-cn/%E7%AE%97%E6%B3%95">算法</a>并集成了有商业版权的<a title="PGPdisk（尚未撰写）" href="/w/index.php?title=PGPdisk&amp;action=edit&amp;redlink=1">PGPdisk</a>工具，有别于开源的GPG（<a title="GnuPG" href="/zh-cn/GnuPG">GnuPG</a>）。PGP的主要开发者为<a title="Philip R. Zimmermann（尚未撰写）" href="/w/index.php?title=Philip_R._Zimmermann&amp;action=edit&amp;redlink=1">菲利普·齐默曼（Philip R. Zimmermann）</a>。齐默曼在志愿者的帮助下，突破政府的禁止，于1991年将PGP在因特网上免费发布。</p>
<p>　　<strong>PGP</strong>是一个桌面工具，在程序中使用相当不便。好在我们可以使用开源的GPG（<a title="GnuPG" href="/zh-cn/GnuPG">GnuPG</a>）在程序代码中写成文件加密。详见如下代码:</p>
<pre lang="C#">using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //EncryptPGP();
            Stopwatch sw = new Stopwatch();
            sw.Start();
            DecryptPGP();
            sw.Stop();
            Console.WriteLine(sw.Elapsed);

            Console.WriteLine("OK");
            Console.Read();
        }
        public static void EncryptPGP()
        {
            ProcessStartInfo pInfo = new ProcessStartInfo();
            pInfo.FileName = @"E:\Test\GnuPGDotNet\GnuPG\gpg.exe";
            pInfo.Arguments = string.Format("  --homedir \"{0}\" --yes --always-trust
             --keyring \"{1}\"  --output \"{2}\" -r zhangwenjie  --encrypt \"{3}\"",
              @"E:\Test\GnuPGDotNet\GnuPG", @"F:\Test\pubring.pkr",
               @"F:\Test\License.txt.pgp", @"F:\Test\License.txt  ");
            pInfo.CreateNoWindow = true;
            pInfo.UseShellExecute = false;

            pInfo.RedirectStandardInput = true;
            pInfo.RedirectStandardOutput = true;
            pInfo.RedirectStandardError = true;
            Process p = Process.Start(pInfo);

            string strInfo;
            while ((strInfo = p.StandardOutput.ReadLine()) != null)
            {
                Console.WriteLine(strInfo);
            }

            p.WaitForExit();

            if (p.ExitCode == 0)
            {
                Console.WriteLine("成功");
            }
            p.Close();

        }
        public static void DecryptPGP()
        {

            ProcessStartInfo pInfo = new ProcessStartInfo();
            pInfo.FileName = @"E:\Test\GnuPGDotNet\GnuPG\gpg.exe";
            pInfo.Arguments = string.Format("  --homedir \"{0}\" --keyring \"{1}\"
           --secret-keyring \"{2}\" --passphrase-fd 0 --output \"{3}\" --decrypt \"{4}\"",
             @"E:\Test\GnuPGDotNet\GnuPG", @"F:\Test\pubring.pkr",
             @"F:\Test\secring.skr", @"F:\Test\Oracle 9i.rar", @"F:\Test\Oracle 9i.rar.pgp");
            pInfo.CreateNoWindow = true;
            pInfo.UseShellExecute = false;
            pInfo.RedirectStandardInput = true;
            pInfo.RedirectStandardOutput = true;
            pInfo.RedirectStandardError = true;
            Process p = Process.Start(pInfo);

            p.StandardInput.WriteLine("123456789");
            p.StandardInput.Flush();
            p.StandardInput.Close();

            string strInfo;
            while ((strInfo = p.StandardOutput.ReadLine()) != null)
            {
                Console.WriteLine(strInfo);
            }

            p.WaitForExit();

            if (p.ExitCode == 0)
            {
                Console.WriteLine("成功");
            }
            p.Close();
        }
    }

}</pre>
<p> 　　其中：pubring.pkr和secring.skr是两个预先生成好的key文件。p.StandardInput.WriteLine(“123456789&#8243;);用来输入解密密码的。</p>
<p>　　希望本文对希望在C#中使用PGP的朋友的帮助。</p>
<p>　　本文首发地址张文杰博客：<a href="http://zhangwenjie.net/" target="_blank">http://zhangwenjie.net</a>（转载请保留）</p>
]]></content:encoded>
			<wfw:commentRss>http://zhangwenjie.net/archives/193/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>微软宣布Visual Studio 2010正式版发布日期</title>
		<link>http://zhangwenjie.net/archives/65</link>
		<comments>http://zhangwenjie.net/archives/65#comments</comments>
		<pubDate>Mon, 19 Oct 2009 08:52:10 +0000</pubDate>
		<dc:creator>zhangwenjie</dc:creator>
				<category><![CDATA[互联网]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[微软]]></category>

		<guid isPermaLink="false">http://zhangwenjie.net/?p=65</guid>
		<description><![CDATA[早在今年5月份微软就发布了Visual Studio 2010和.NET Framework 4.0的首个Beta测试版，今天微软宣布已经为MSDN订阅用户提供了VS 2010的第二个Beta版，普通用户将在10月21日获取免费下载...]]></description>
			<content:encoded><![CDATA[<p>早在今年5月份微软就发布了Visual Studio 2010和.NET Framework 4.0的首个Beta测试版，今天微软宣布已经为MSDN订阅用户提供了VS 2010的第二个Beta版，普通用户将在<strong>10月21日</strong>获取免费下载。</p>
<p>此外，微软还宣布了Visual Studio 2010的官方正式发布日期，定在<strong>2010年3月22日</strong>，并且表示这将是近几年来Visual Studio和.NET Framework最重要的一次版本升级，新增功能包括Windows 7和SharePoint 2010工具以及对并行编程的支持等。</p>
<p>VS2010开发代号“Rosario”(阿根廷港市罗萨里奥)，除了上述功能外还在以下方面进行了改进：</p>
<ol>
<li>完善了Visual Studio IDE；</li>
<li>Visual Basic和C#语言：在Visual Studio 2010中，VB和C#语言的演变是对等的，开发人员可以根据自己的爱好选择任意一种语言；</li>
<li>Visual Studio 2010包括一种新的.NET Framework语言：F#；</li>
<li>Web开发：VS 2010改进了代码编写的速度，简化了Web开发，还支持基于MVC的Web应用等；</li>
<li>WPF和Silverlight：改进了对WPF和Silverlight应用程序的开发；</li>
<li>完善了Visual C++功能。</li>
</ol>
<p>VS2010的截图如下：</p>
<div class="wp-caption aligncenter" style="width: 510px"><img class=" " title="Visual Studio 2010外观截图" src="http://img2.zol.com.cn/product/28_500x2000/878/ce2jL5wFm2n8s.jpg" alt="VS2010" width="500" height="400" /><p class="wp-caption-text">Visual Studio 2010外观截图</p></div>
<div class="wp-caption aligncenter" style="width: 510px"><img title="Visual Studio 2010外观截图" src="http://img2.zol.com.cn/product/28_500x2000/879/ce4UiZuRkuOL2.jpg" alt="Visual Studio 2010外观截图" width="500" height="354" /><p class="wp-caption-text">Visual Studio 2010外观截图</p></div>
<p>官方下载Visual Studio 2010 Beta 1：<br />
<a style="color: #0000ff; text-decoration: underline;" href="http://blogs.msdn.com/onoj/archive/2009/05/19/visual-studio-2010-beta-1-download-options.aspx" target="_blank">http://blogs.msdn.com/onoj/archive/2009/05/19/visual-studio-2010-beta-1-download-options.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://zhangwenjie.net/archives/65/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

