存档:2009年, 七月

GetType和typeof

类别: C# 发表评论

typeof是运算符,GetType是System.Object的方法 GetType方法获取一个对象的类型(Type),typeof操作符获取一个类型对应的System.Type对象 typeof运算符,不能够被重载,作用于类型。typeof也可以用来获取泛型的类型。 GetType用来获取运行时的类型,因此只有建立一个实例后才能够调用。

[译]使用PowerShell的10个小建议

类别: PowerShell 发表评论

一篇比较老的文章了,06年的,原文在这。 使用PowerShell的10个小建议(1) 使用PowerShell的10个小建议(2) 使用PowerShell的10个小建议(3) 使用PowerShell的10个小建议(4) 使用PowerShell的10个小建议(5)

一道javascript的笔试题

类别: javascript 发表评论

这样一段js代码,要求补全代码,使得能正确执行,弹出“it works!” 的对话框: test1=new Test(); test1.setNumber(3);   test2=new Test(); test2.setNumber(2);   if(test1+test2==5) alert("it works!"); 当然懵了,后来请教下牛人,像下面这样就可以了: function Test() { var value=0; this.setNumber=function(num) { value=num; } /* this.toString=function()*/ this.valueOf=function() { return value; } }   test1=new Test(); test1.setNumber(3);   test2=new Test(); test2.setNumber(2);   if(test1+test2==5) alert("it works!"); 由于js中没有办法实现运算符重载,只能用其他方式来模拟。js的对象都包含toString()和valueOf()方法,toString()方法返回对象的原始字符串表示,而valueOf()方法返回最适合该对象的原始对象值,而且在很多时候,二者返回的值相同。valueOf() 方法通常由 JavaScript 在后台自动进行调用,而不是显式地处于代码中。在这个例子中,用valueOf比toString要好些。 参考: [1] ECMAScript Function 对象(类)  http://www.w3school.com.cn/js/as_js_functions_function-object.asp [2] [...]

C#连接SQL Server

类别: C# 发表评论

步骤: 创建一个SqlConnection连接(注意连接字符串的写法),打开连接 创建一个SqlCommand,并设置Connection和CommandText 创建一个SqlDataAdapter,设置SelectCommand 创建DataSet,并填充  using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient;   namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }   private void Form1_Load(object sender, EventArgs e) { BindData(); }   private void BindData() { // [...]