顯示包含「C#」標籤的文章。顯示所有文章
顯示包含「C#」標籤的文章。顯示所有文章

2012年11月8日星期四

C# 5.0新功能 - Caller Information Attributes

PHP語言中,有樣東西叫Magic Constants,即大家常見的"__LINE__","__FILE__"等等。

這亦是我渴望在C#出現的東西,因為這對Debug或者是Logging都很有用。

C# 5.0就剛巧新增這個功能,叫做Caller Information,介紹一下。

取錄自MSDN,Caller Information有三個主要Attribute,分別為 :
  • CallerFilePathAttribute
    • Full path of the source file
  • CallerLineNumberAttribute
    • Line number in the source file at which the method is called.
  • CallerMemberNameAttribute
    • Method or property name

使用方法很簡單,只需把Attribute放置在Optional Parameters前端,就如一般的Class Attribute一樣。
以下面程式碼為例:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.CompilerServices;

namespace WhoCallMyFunction
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //Comment lines will not affect the LineNumber.
            MyFunction(" I Know That Feel Bro.");
        }

        private void MyFunction( string WhyCallMe,
                [CallerMemberName] string MemberName = "",
                [CallerFilePath] string FilePath = "",
                [CallerLineNumber] int LineNumber = 0
            )
        {
            Console.WriteLine("\r\n WhyCallMe : {0} \r\n " + 
                                       "Time : {1} \r\n " + 
                                       "Member name : {2} \r\n "+
                                       "FilePath : {3} \r\n "+
                                       "LineNumber : {4} ", 
                                       WhyCallMe, DateTime.Now.ToString(), MemberName, FilePath, LineNumber.ToString());
        }
    }
}

最後便會輸出
WhyCallMe :  I Know That Feel Bro. 
 Time : 8/11/2012 15:21:32 
 Member name : Form1_Load 
 FilePath : c:\Users\Ming\Documents\Visual Studio 2012\Projects\WhoCallMyFunction\WhoCallMyFunction\Form1.cs 
 LineNumber : 20 

雖然這是C# 5.0的新功能,但原來有方法可以令舊版本都支援。
詳細請見:
Using C# 5 caller info attributes when targeting earlier versions of the .NET framework
Calling C# 4/3/2.... Using the new C# 5 Caller Information with C# 2,3,4...

2009年10月27日星期二

ASP.NET Server Side & Client Side資料加密處理

對於ASPX網頁上暫存資料方面,ServerSide最常用多數都是用Session,ClientSide應該都是ViewState吧,前者應該沒有太多保安問題,但後者的ViewState其實要Decode根本不難,所以加密功夫其實很重要的。近期工作上經常要使用 jQuery + Web Service處理資料,有些敏感資料會經JSON傳回Browser,又或者經Hidden Field傳回Server,有些情況是很難避免的 (特別是上司要求...),我看過有些懶人只用Base64轉碼就當是加密其實真的很危險。

.NET Framework其實本身在System.Security.Cryptography NameSpace下已經提供了大量加密方式,在MSDN看過後,取了幾種針對String加密的,做了少少資料搜集有關 3DES / DES / RSAAES (Rijndael) 的比較,其實4種方法同樣都需要一項Key才可以進行正常解密,所以即使知道你網頁中加密後的字串,而不知道你所設定的Key都不可能正常解密的。

論安全性,粗略評估後的排行應該是 AES (Rijndael) > AES > 3DES > RSA / DES。

至於使用方面,Client-Side可以使用以下的Javascript 解密AES:
http://www.movable-type.co.uk/scripts/aes.html

Server-Side方面,其實MSDN上已有很清晰的Sample,以下就是使用AES (Rijndael)方式對String進行encrypt和decrypt的例子。

using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;

class RijndaelSample
{

static void Main()
{
try
{
// Create a new Rijndael object to generate a key
// and initialization vector (IV).
Rijndael RijndaelAlg = Rijndael.Create();

// Create a string to encrypt.
string sData = "Here is some data to encrypt.";
string FileName = "CText.txt";

// Encrypt text to a file using the file name, key, and IV.
EncryptTextToFile(sData, FileName, RijndaelAlg.Key, RijndaelAlg.IV);

// Decrypt the text from a file using the file name, key, and IV.
string Final = DecryptTextFromFile(FileName, RijndaelAlg.Key, RijndaelAlg.IV);

// Display the decrypted string to the console.
Console.WriteLine(Final);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

Console.ReadLine();
}

public static void EncryptTextToFile(String Data, String FileName, byte[] Key, byte[] IV)
{
try
{
// Create or open the specified file.
FileStream fStream = File.Open(FileName, FileMode.OpenOrCreate);

// Create a new Rijndael object.
Rijndael RijndaelAlg = Rijndael.Create();

// Create a CryptoStream using the FileStream 
// and the passed key and initialization vector (IV).
CryptoStream cStream = new CryptoStream(fStream, RijndaelAlg.CreateEncryptor(Key, IV), CryptoStreamMode.Write);

// Create a StreamWriter using the CryptoStream.
StreamWriter sWriter = new StreamWriter(cStream);

try
{
// Write the data to the stream 
// to encrypt it.
sWriter.WriteLine(Data);
}
catch (Exception e)
{
Console.WriteLine("An error occurred: {0}", e.Message);
}
finally
{
// Close the streams and
// close the file.
sWriter.Close();
cStream.Close();
fStream.Close();
}
}
catch (CryptographicException e)
{
Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
}
catch (UnauthorizedAccessException e)
{
Console.WriteLine("A file error occurred: {0}", e.Message);
}

}

public static string DecryptTextFromFile(String FileName, byte[] Key, byte[] IV)
{
try
{
// Create or open the specified file. 
FileStream fStream = File.Open(FileName, FileMode.OpenOrCreate);

// Create a new Rijndael object.
Rijndael RijndaelAlg = Rijndael.Create();

// Create a CryptoStream using the FileStream 
// and the passed key and initialization vector (IV).
CryptoStream cStream = new CryptoStream(fStream, RijndaelAlg.CreateDecryptor(Key, IV), CryptoStreamMode.Read);

// Create a StreamReader using the CryptoStream.
StreamReader sReader = new StreamReader(cStream);

string val = null;

try
{
// Read the data from the stream 
// to decrypt it.
val = sReader.ReadLine();


}
catch (Exception e)
{
Console.WriteLine("An error occurred: {0}", e.Message);
}
finally
{
// Close the streams and
// close the file.
sReader.Close();
cStream.Close();
fStream.Close();
}

// Return the string. 
return val;
}
catch (CryptographicException e)
{
Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
return null;
}
catch (UnauthorizedAccessException e)
{
Console.WriteLine("A file error occurred: {0}", e.Message);
return null;
}
}
}

2008年11月24日星期一

C# 認識Enumeration - enum Keyword

Enumeration(列舉型別)不是常用的類型,不過有時候做對比的程序,Enum就起了作用。自己寫程式都是比較少用Enum,所以溫故知新,在此講解一下Enum的用法。

找一個例子,假如你替一間遊戲店寫一個系統,需要做以下功能:
- 由產品名稱找到售價
- 由售價找到產品名稱
- 由售價去判斷產品是否存在
那Enum列舉型別都大派上場了。

首先我們簡單地了解一下如何 Construct Enum :
開一個新的Windows Form :
namespace Enum_Example_1
{
enum GameConsole
{
XBox360,
PS3,
Wii,
NDSL,
PSP
};

public partial class Form1 : Form
{
public Form1()
{ InitializeComponent();}

private void Form1_Load(object sender, EventArgs e)
{
GameConsole IHaveThisConsole = GameConsole.XBox360;
Console.WriteLine((IHaveThisConsole == GameConsole.PS3).ToString()); //False
Console.WriteLine((IHaveThisConsole == GameConsole.XBox360).ToString()); //True
}
}
}

在這裡我們可以看到Enum本身就有對比性,即使你不預設任何Value,但是enum類型本身就是可以分別是否相同。

2008年11月3日星期一

New Features in C# 4.0

PDC 2008中,其中一段演講是介紹C# 4.0, 新版本的C#主要新增加4樣東西,其實改動不多是正常,別忘記現在的C#版本3.0,但亦是過渡版本的3.5,所以3.5->4.0改動不多亦是正常.
新特點有:
  • Dynamic lookup
  • Named and optional parameters
  • COM specific interop features
  • Variance

我比較關注Dynamic lookup和Named and optional parameters.
(以下例子是引用Microsoft的官方文件)

2008年8月4日星期一

LINQ : Using Lambda Expression to AddRange()

在LINQ中使用Lambda Expression,我們可以有效地extract出Anonymous Types中的values.

Example :
public List<string> GetList()
{
List<string> pList = new List<string>();
DataClasses_Store DataContext = new DataClasses_Store();
//Select the customer where live in "HongKong" and Take 100 records
var select = (from c in DataContext.customer_info
where c.customer_location.Equals("HongKong")
orderby c.reg_date descending
select new { c.customer_id , c.customer_name } ).Take(100);
//Fill the List
foreach (var s in select)
{
pList.Add(c.customer_id + " " + c.customer_name);
}
return pList;
}

使用Foreach方法都是一般網上Example做法,但是我們可以使用Lambda Expression並轉換成IEnumerable達至AddRange的要求。

public List<string> GetList()
{
List<string> pList = new List<string>();
DataClasses_Store DataContext = new DataClasses_Store();
//Select the customer where live in "HongKong" and Take 100 records
var select = (from c in DataContext.customer_info
where c.customer_location.Equals("HongKong")
orderby c.reg_date descending
select new { c.customer_id , c.customer_name } ).Take(100);
//Fill the List
pList.AddRange(select.Select(p => p.customer_id + " " + p.customer_name).AsEnumerable());
return pList;
}

2008年7月2日星期三

.NET 網摘 (02/07/2008)


Microsoft's Opinionated Misfit Geek - The Everlasting Question - Should I choose VB.NET of C#
(沒完沒了的問題,其實在高手層面都依然在討論,連Microsoft的專家都要寫Blog討論一翻)
http://www.misfitgeek.com/The+Everlasting+Question+Should+I+Choose+VBNET+Of+C.aspx

Create iPhone Applications Using ASP.NET AJAX
By Steve C. Orr
http://steveorr.net/articles/iPhone.aspx

Build a Web Chat Application using ASP.Net 3.5, LINQ and AJAX (in C# 3.5)
By Junnark Vicencio's Blog
http://www.junnark.com/Articles/Build-a-Web-Chat-Application-Using-ASP-Net-LINQ-and-AJAX-CS.aspx

Complex Data Binding with the Accordion Control
By Brian Mains
http://aspalliance.com/1674_complex_data_binding_with_the_accordion_control

Generating image thumbnails in ASP.NET
By Bertrand Le Roy
http://dotnetslackers.com/articles/aspnet/Generating-Image-Thumbnails-in-ASP-NET.aspx

2008年5月8日星期四

如何用C#破Xanga Sign-in Lock

XangaSpy我相信好多人都用過吧~我試過在Alexa把XangaSpy和一些香港知名網站比較,如果Alexa的統計正確的話,XangaSpy的流量是和she.com 相若。一個小小網絡程式流量與討論區可比,都算是不錯。如果冇記錯,XangaSpy是高登網友用PHP寫出來的。但其實用DotNet都可以做到XangaSpy的效果,即是破解Sign-In Lock / 重新format一次文章等等,以下我就和大家交流一下是怎樣做到的。

1. 我隨意找來一個是有Sign-In Lock的用戶做測試,大家可見在沒有Login情況下,是沒有權限瀏覽內容的。
2. 我又隨意咁申請了一個Xanga戶口,Sign-in後,就可以正常瀏覽內容。如圖所見,我可以使用一些Firefox 看HTTP Header的Extension或一些Inspector軟件去得知傳送了什麼Header至Xanga伺服器,在這篇文章中,我只需要兩個Header,分別是Referer 和 Cookie。先解釋一下這兩個是什麼,Referer是告訴Xanga知你是經由什麼地方傳送到這個網址;Cookie在這裡純粹是一個id,真正意義是之後一連串的value,紀錄了你的login資料,Xanga就是用這個value去分辦你是否已Sign-In。
3. 開Visual Studio,建立一個Project,其實可以是C#/Visual Basic/ASP.NET,沒所謂的,我在這裡示範用C#而已,如圖把Control放上兩個TextBox,一個Single Line用作Xanga ID,另一個Multi Line用作內容,再加一個button。
4. 新增一個Class,叫Xanga_Hack,然後Create一個Function叫XangaHeader,return 類型是WebHeaderCollection,把我們剛剛說的Referer 和 Cookie 的數值Add進至Collection中。如果你想完美一點,你可以參照你的HTTP Header Parser,把其他Key和Value也加進Collection中。
5. 再新增一個Class,叫TCP_Function,用TCPClient去接收HTML資料,然後放置在TextBox中,這時你應該可以見到文章的內容了。

拿回來的一堆HTML,其實你可以使用regex去把題目,內文Extract出來。就我略略睇過不同Xanga的DOM,不同的Theme會生產不同的結構。例如以文章為例,每一個Xanga頁面都必定會有一個id是maincontent的container去顯示內容,
但有些Theme是會生產<div id="maincontent">; 有一些會生產<td id="maincontent">;,所以這才是要下功夫的地方。就好似XangaSpy,其實有一些Xanga它是暫時不支援的,例如: http://www.xanga.com/MandyStarz,這Account本身沒有Sign-In Lock,但假如你使用XangaSpy看,是顯示不到內容出來的,我估計是因為這個Theme本身沒有任何一個Tag的id是maincontent所致。另外一個比較容易的方法是進它們的archives Page找文章計和連結,但這方法理論上比較花時間。

以上就是我小小心得,或者大家會問,為什麼你不做ASP.NET版本的XangaSpy? 原因就是我覺得其實沒有什麼好研究,只是與無名小站一樣,都是玩弄著HTTP Header而已,而且Xanga都是小朋友玩意。至於破解Xanga中的Friend-Lock,我覺得沒有什麼可能,可以假設,Xanga Check Friend-Lock 與Sign-In Lock是同一方法,雖然或者可以經Google Search,得知誰是[朋友],但怎樣演算一個Account資料至Header中就已經是問題所在。

2008年3月31日星期一

C# - Worth To Use Extension Methods

對於經常在VisualBasic和C#之間往來的我來說,會明白到C# Strong Type的好處,但同時亦覺得VB語法寬鬆的好處.
因為在C#中要經常做轉型(Convert.ToString / .ToString etc) , 在VB中,Object可以和Integer相加 , 在C#的話, 就肯定是出現Error.

這一陣子寫Silverlight的時間,經常有很多object type出現,由於是coordinate,所以必須轉換成Double.

就以下面的Code為例,ImgBall的GetValue是object type,不能就這樣做operation,所以必須用Convert.ToDouble轉型,但單單一小節Code,已經出現3次:
if (Convert.ToDouble(ImgBall.GetValue(Canvas.LeftProperty)) < Convert.ToDouble(ImgPaddle.GetValue(Canvas.LeftProperty)) + 5)
{
ImgBall.SetValue(Canvas.LeftProperty, Convert.ToDouble(ImgPaddle.GetValue(Canvas.LeftProperty)) + 5);
}

Extension Methods的出現可大大降低程式碼的長度,效能雖然沒有得益,但增加程式碼的可讀性.
以下我就示範一下如何透過Extension Methods令整個程序更美觀.

建立一個Class檔案 (ext.cs) ,在Namespace低下加入:
public static class ext
{
/// <summary>
///  Get Dependency Object and Convert to Double.
/// </summary>
public static Double GetDouble(this Image img, DependencyProperty property)
{
return Convert.ToDouble(img.GetValue(property));
}

/// <summary>
///  Get Canvas.LeftProperty From Image.
/// </summary>
public static Double GetCanvasLeft(this Image image)
{
return GetDouble(image, Canvas.LeftProperty);
}
/// <summary>
///  Get Canvas.TopProperty From Image.
/// </summary>
public static Double GetCanvasTop(this Image image)
{
return GetDouble(image, Canvas.TopProperty);
}
}

以上程序就是把Property引入,並進行類型轉換,要注意緊記加入"static"的Modifier.

回到開始的部份,我們已經可以在Image Member中找到GetCanvasLeft 和GetCanvasTop,直接引用就已經可以得到Double類型的數值了,是不是簡短很多呢~
if (ImgBall.GetCanvasLeft()  < ImgPaddle.GetCanvasLeft() + 5)
{
ImgBall.SetValue(Canvas.LeftProperty, ImgPaddle.GetCanvasLeft() + 5);
}

其實某程度上Extension Methods和傳統的Function相似,都是可以引入Parameter , return數值等等, 但Extension Methods是指定在某一個類別下衍生出功能,當實際使用時就會依據類別而出現於Member List中,亦算是符合一般程式概念.

2008年3月14日星期五

LINQ 學習筆記 - LINQ to SQL

記得當時ADO.NET出現其中的一個目的,就是要提供一個Layer可以Offline作業,事實上利用DataSet, DataTable般的In-memory資料集合,的確對Server和程式本身有不少的好處。

LINQ to SQL是LinQ架構下重要的子集,在LINQ Providers中,可以大致分為 :
  1. LINQ to Objects
  2. LINQ to XML
  3. LINQ to SQL
  4. LINQ to DataSets
透過LINQ to SQL,我們可以把整個資料庫轉換成Data Model,當中包含Table的結構,DataType等等。而Data Field本身亦會隨Table成為Member角色,而產生的DataContext亦充當了一個Gateway,例如以往我們使用SQL Command時,發生Command String錯誤,有時會是Remote Side 回存的SQL Exception,但使用LINQ to SQL後,在Design Time時,已經可能知道錯誤,這大大加強資料庫的可程式性。

現在我就示範如何去把Database轉成LINQ 上使用的Data Class。

我使用了SQL 2005的AdventureWorks Sample Database ,在Visual Studio中的Database Explorer加入資料連接 ,Right Click Project => Add New Item ,再選 [ LINQ to SQL Class ] ,之後就會新增一個dbml檔案。

我選用了Contact / Product / Customer / SalesOrderHeader / SalesOrderDetail 五個Table, 在Database Explorer 選取後,把它們Drag & Drop至中間的位置後,Visual Studio 便會自動建立Class至dbml檔案。

greenshot_2008-03-13_16-11-59.pnggreenshot_2008-03-13_16-29-21.png

新增一個Form , 隨意加入一個DataGridView和兩個ComboBox後,建立一個BuildGrid的程序,輸入Code之後,已經可以做到基本的DataBinding了。(如下圖)

greenshot_2008-03-13_16-32-26.png greenshot_2008-03-13_16-35-23.png

嚴格來說,只需要三行的程式碼就可以 :
DataClass.infodata1_DataContext dc = new LINQPlayer.DataClass.infodata1_DataContext();
var select = (from c in dc.Contact where c.ContactID != null select new { c.ContactID , c.NameStyle, Name = (c.Title + ' ' + c.FirstName + ' ' + c.MiddleName + ' ' + c.LastName), c.EmailAddress, c.Phone, c.ModifiedDate }).Take(Convert.ToInt32(cboTake.SelectedItem)).Skip(Convert.ToInt32(cboSkip.SelectedItem));
dgv1.DataSource = select;


不用如ADO.NET般建立SQL Connection ,因為在剛才建立的dbml檔案,內裡已經有Connection String,同時亦免除SQL Command, SQLDataReader 等等,因為當中的var select是Anonymous types , 具有直接存放Data Collection的能力。透過LinQ的Query Syntax,你可以使用屬於extension method,如[skip] , [take] 去做有條件性選擇。

greenshot_2008-03-13_16-49-10.png

作者 : 達Ming
最後更新 : 13-3-2008

原創文章 - 轉貼時請註明出處 : http://tatmingstudio.blogspot.com/2008/03/linq-linq-to-sql.html
(有錯請留言更正,多多指教)

2008年3月13日星期四

LINQ 學習筆記 - Data Class / Data Context

DataClass是可以自行編寫的,但我相信非必要都不會那樣做,因為一個Database動輒有二三十個Table,Column不計其數,要自己編寫的話,真是要花很多時間,而且Visual Studio中又有提供Data Model的Generator。不過學習 LINQ之前,我們都看看DataClass是怎樣做Mapping。

greenshot_2008-03-13_14-07-31.png

我使用了簡單的NorthWind Access DB ,為"Customers"的Table 建立一個Class檔案:
class DCClass
{
// 取得Customers的Table , 進行Table Mapping
[Table(Name = "Customers")]
public class CustomerDC
{
// Column : CustomerID
[Column(IsPrimaryKey = true)]
public string CustomerID { get; set; }
// Column : Name 並轉成 ContactName
[Column(Name = "ContactName")]
public string Name { get; set; }
// Column : City
[Column]
public string City { get; set; }
}
}


在程式中,我就可以使用這個Class了,以Button為例 :
private void button2_Click(object sender, EventArgs e)
{
//建立IDbConnection
IDbConnection MyConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Nwind.mdb;User Id=admin;Password=;");
//建立dc為新的DataContext
DataContext dc = new DataContext(MyConnection);
//建立EntityType的Customers 並取得DCClass中的CustomerDC結構
Table<dcclass.customerdc> Customers = dc.GetTable<dcclass.customerdc>();
//可以直接使用LinQ語法去做Query了
DataGridView1.DataSource = from c in Customers where c.CustomerID.StartsWith("A") select new { MyCustomerID = c.CustomerID, MyCustomerName = c.Name, MyCity = c.City };
}


以上就是基本的DataClass , DataContext , LinQ的示範,但試想下,假如你的Database有廿多個Table,每個Table就有十多個Column的話,可以想像編寫DataClass是十分花時間的。 下一次,我就會示範如何使用LinQ to SQL Designer快速地建立Data Class。

作者 : 達Ming
最後更新 : 13-3-2008

原創文章 - 轉貼時請註明出處 : http://tatmingstudio.blogspot.com/2008/03/linq-data-class-data-context.html
(有錯請留言更正,多多指教)

2008年1月18日星期五

學習C# 3.0的好網推薦

這幾天都學習C# 3.0的新功能,主要都是ADO.NET Entity Framework,LINQ和 Extension methods,
一路玩LINQ,就一路有疑問,就是何時應該使用LINQ。看過很多Example , 都是先建立一個Class,去把TableColumn先做Mapping,再由DataContext去把Table實體化。

之後很多都會直接做DataSource 或者轉做 Anonymous types,但是我昨天就試過把LINQ的Table轉回至DataTable,最後都不知怎樣做,上Google Search找回來的竟然是使用Foreach去讀出Anonymous types,再填入Datarow再加進DataTable....
完成後的Code比傳統使用ADO.NET更長更複雜....我覺得如純粹做Data-Mining,使用LINQ有點冗長。

但相反,由DataSet 中,使用LINQ把資料讀出就比較直接先進.

最後到Extension methods ,十分好用而且簡單,可以看看:
Using the New Extension Methods Feature in C# 3.0
http://www.developer.com/net/csharp/article.php/3592216
C#之 VS2008 之 Extension Methods
http://www.cnblogs.com/hanxianlong/archive/2007/11/06/951446.html
C# 3.0 feature 2--Extension methods
http://www.cnblogs.com/hiber/archive/2007/04/29/725617.html

清理Bookmark 時看到這幾個網頁,我覺得是寫得不錯的,都不是新文章,都是C# 2.0的東西.

Iterator :
http://www.cnblogs.com/JimmyZhang/archive/2007/08/22/865245.html

.NET Framework 2.0 中的Generic Class :
(如你還在使用ArrayList,要看看box和unbox對效能的影響)
http://www.cnblogs.com/JimmyZhang/archive/2007/08/04/842663.html

Delegate & Event :
http://www.blueidea.com/tech/program/2007/4959.asp

C# 2.0中的Nullable Type
http://dotnetframework.blogspot.com/2006/08/c-20nullable-type.html

2007年11月24日星期六

C# Version 3.0 Specification

http://msdn2.microsoft.com/en-us/library/ms364047(VS.80).aspx

Visual Studio 2008 and .NET Framework 3.5 released!!!


就如原定日期,VS2008終於推出~官方網頁亦更新了,Express版官網使用黑色設計,很神秘的感覺^^
同樣有三大版本 : Professional / Standard / Express
最關心的肯定就是免費且可商業用的Express版本,除了基本VisualBasic / C# / C++ / Visual Web Developer 外,VS2008還多了一個叫Popfly的東西.
對我來說,除了WPF,LinQ外,最想試試VWD整合Expression Web後是如何~Microsoft亦很好地整了一個All-in-One DVD ISO,不用分開下載和安裝了~

Visual Studio Home
http://msdn2.microsoft.com/en-us/vstudio/products/default.aspx
Visual Studio 2008 Express Home
http://www.microsoft.com/express/default.aspx
Download the Visual Studio 2008 Express Edition All-in-One DVD
http://www.microsoft.com/express/download/offline.aspx

Resource:
An Overview of Microsoft Visual Studio 2008 White Paper
Visual Studio 2008 and .NET Framework 3.5 Training Kit
Get up to speed on Visual Studio 2008
Visual C# 2008 Keybinding Reference Poster
.NET Framework 3.5 Common Namespaces and Types Poster

2007年11月13日星期二

由VB.NET轉寫C#的後遺症

為未來著想,現在我新Project都盡量用C#寫,除左想識多一種語言之外,日後轉往其他語言都會易一些。

其實由VB.NET轉寫C#真的沒有難度可言,只是事乎肯不肯去習慣新Syntax,能不能排除起步時比正常慢的Coding速度,

當然先決條件就是你對VB.NET已經熟悉,和不是死記Syntax去操作.NET Framework。

就像我自己,這個星期把部份Project轉成C# Port,短短的時間我現在都可以寫C#了~(自信-_-")
不過就令我想起早6,7年我還是寫VB6的時候,經常網上見到有人說寫VB會壞手勢,到現在我主力寫C#時,就覺得所言甚是。

或者未接觸過的人不知道,在C#中,是case-sensitive,如果你寫"If..."是不接受的,
Visual Studio亦不會幫你轉換,要寫做小寫"if",當然Class,Member,Method等等都是,

其次是C#是Strong Type語言,以往在VB中,interger,object,string如果是數字的話,都可以相加,或者用"&"做String,
但在C#中,一定要指名Type才可以。

很多情況下都要轉Type,始終C#是一種很嚴謹的語言。
還有很多很多的不同,在此不能盡錄。不過的確經常VB.NET <> C#交替使用會令syntax在腦中打結,有時寫C#會打Dim;寫VB.NET打"//"就Comment....

但我轉移C#的參考材料就可以睇返我之前寫的Blog文 : 開始學習C#

2007年5月18日星期五

開始學習C#

與其說是學習C#,不如說實在一點,是學習C#語法。

就如之前所說,一直寫Visual Basic的我,轉寫C#實在很不慣,程式碼多了很多 "{" 和 "}",而且經常漏了結尾的";"。

其實我從來不覺得C#比VB有什麼優勝,好像到現在很多人都錯誤理解(C#比VB強)的想法,只能怪他沒有認真看過Comparison,而且我更不覺得同一個程序下,VB 的Code比C#長有什麼問題或不好,由VB一出世開始都主張VB言語是具有極佳的可視性和可讀性。

不過我學C#只是覺得既然自己全心向.NET發展,而VB和C#有互換性,分別又只是語法上,學多一種語言都是好事。
只需要把時間花在龜速的Coding就可以了。

找到一些很好的Reference書藉,對VB.NET用家學習C#都有幫助,eBook的話大家可以經網上得到。
合共不到幾MB,但若果要買都很平,上Amazone買都只是不到$HKD$100一本而已。

O'Reilly C# Language Pocket Reference
O'Reilly C# & VB.NET Conversion Pocket Reference
McGraw.Hill.Osborne : C# 2.0: The Complete Reference, Second Edition
Other:
VB.NET and C# Comparison

2006年3月15日星期三

VB.NET VS C#


VB.NET vs C# 的比較,沒完沒了~
剛本想上Google Search一下又有沒有VB 2005 VS C# 2.0 的議題時,卻找到Usenet 上一些舊有的討論.他們不是潑婦罵街,是理性討論的.細心閱讀後,便Bookmark下來.
如你還苦思選擇VB.NET 還是C#好,建議你看一看以下連結吧. 都幾有趣的~
Google Group:
Yet again another VB.NET vs C# debate
VB.NET vs C# (1) (2) (3) (4)
Programmer's Corner - C# vs. VB.Net
VB.NET vs C# Syntax 語法戰決 & 比較