April 09
日报/4/10/2008
在c#中(int)、int.Parse()、int.TryParse、Convert.ToInt32()四种转换的区别
1、(int)是一种类型转换;当我们从int类型到long,float,double,decimal类型,可以使用隐式转换,但是当
我们从long类型到int类型就需要使用显式转换,否则会产生编译错误。 2、int.Parse()是一种类容转换;表示将数字内容的字符串转为int类型。 如果字符串为空,则抛出ArgumentNullException异常; 如果字符串内容不是数字,则抛出FormatException异常; 如果字符串内容所表示数字超出int类型可表示的范围,则抛出OverflowException异常; 3、int.TryParse 与 int.Parse 又较为类似,但它不会产生异常,转换成功返回 true,转换失败返回 false。最后一个参数为输出值,如果转换失败,输出值为 0 4、Convert.ToInt32()是一种类容转换;但它不限于将字符串转为int类型,还可以是其它类型的参数; 比较: Convert.ToInt32 参数为 null 时,返回 0; int.Parse 参数为 null 时,抛出异常。
Convert.ToInt32 参数为 "" 时,抛出异常; int.Parse 参数为 "" 时,抛出异常。
Convert.ToInt32 可以转换的类型较多; int.Parse 只能转换数字类型的字符串。
关于对象直接量(JS第四版50页3.5.2) |
定义对象直接量的语法,使你能创建对象并定义它的属性。对象直接量由一个列表组成,列表元素用冒号分隔的属性/值对,元素之间用逗号隔开了,整个列表包含在花括号之间。For Exemple:var point = {x:2.3,y:-1.2}; 对象直接量也可以嵌套,例如:var rectangle = { upperLeft:{x:2,y:2},lowerRight:{x:4,y:4}}; 最后说明的是:对象直接量中的属性值不必是常量,它可以是任意的JavaScript表达式。 例如 EDoc2里面的:
/**
* Copyright (c) 2007 XXXX.Crop. All rights reserved.
* @Author dxh
*/
// EDoc2.Department
JueKit.Type.registerNamespace("EDoc2");
EDoc2.Department = JueKit.Type.createClass("EDoc2.Department", null,
{
ctor : function(data)
{
this._data = data;
this.isChildrenDepartmentsLoaded = false ;
this.isUsersLoaded = false;
//var dvDeptUser = new EDoc2.DepartmentUserDataView(this);
// this._defaultView = dvDeptUser;
},
get_defaultView : function()
{
return this._defaultView;
},
// IDataRow Members
getColValue : function(name)
{
if(name == "id")
{
return this._id;
}
if(name == "type")
{
return EDoc2.MemberType.department;
}
return this._data.loginName;
},
get_childDepartmentLoaded : function()
{
// if ( this.isChildrenDepartmentsLoaded )
// {
// return true;
// }
if(!this._departments)
{
// 如果没有加载直接返回false
return false;
}
return true;
// 否则判断缓存是否过期
if(new Date() - this._tmFoldersLoad > EDoc2.OrgnizationClient._cacheExpired)
{
return false;
}
return true;
},
get_childUsersLoaded : function()
{
// if ( this.isUsersLoaded )
// {
// return true ;
// }
if(!this._users)
{
// 如果没有加载直接返回false
return false;
}
return true;
// 否则判断缓存是否过期
if(new Date() - this._tmFilesLoad > EDoc2.theOrgMng._cacheExpired)
{
return false;
}
return true;
},
notifyDepartmentsLoad : function(departments)
{
this._tmFoldersLoad = new Date();
this._departments = [];
var department;
for(var i=0; i<departments.length; i++)
{
department = EDoc2.theOrgMng._departments[departments[i].id];
if(department)
{
department._data = departments[i];
}
else
{
department = new EDoc2.Department(departments[i]);
EDoc2.theOrgMng._departments[department._data.id] = department;
}
this._departments[this._departments.length] = department;
}
},
notifyUsersLoad : function(users)
{
this._tmFilesLoad = new Date();
this._users = [];
var user;
for(var i=0; i<users.length; i++)
{
user = EDoc2.theOrgMng._users[users[i].id];
if(user)
{
user._data = users[i];
}
else
{
user = new EDoc2.User(users[i].id,users[i]);
EDoc2.theOrgMng._users[user._data.id] = user;
}
this._users[this._users.length] = user;
}
},
loadChildren : function(loadType, cbFunc, oScope)
{
// 如果不指定加载的类型,默认加载部门
loadType = parseInt(loadType);
if(!loadType)
{
loadType = EDoc2.LoadChildrenType.loadDepartments;
}
// 如果已经加载过部门,则不再加载
if(this.get_childDepartmentLoaded())
{
loadType &= ~EDoc2.LoadChildrenType.loadDepartments;
}
// 如果已经加载过用户,则不再加载
if(this.get_childUsersLoaded())
{
loadType &= ~EDoc2.LoadChildrenType.loadUsers;
}
// TODO:职位
if(loadType)
{
var func = function(text)
{
this.__cbLoadChildrenS(text);
cbFunc.call(oScope, this);
};
EDoc2.theOrgMng.postBack("LoadDepartmentChildren", {deptId : this._data.id, loadType : loadType}, func, this);
}
else
{
cbFunc.call(oScope, this);
}
},
__cbLoadChildrenS : function(text)
{
var result = text.toObject();
var loadType = 0;
if(result.departments)
{
loadType |= EDoc2.LoadChildrenType.loadDepartments;
this.notifyDepartmentsLoad(result.departments);
}
if(result.users)
{
loadType |= EDoc2.LoadChildrenType.loadUsers;
this.notifyUsersLoad(result.users);
}
this.isChildrenDepartmentsLoaded = true ;
this.isUsersLoaded = true;
EDoc2.theOrgMng.notifyChildrenDepartmentLoaded(this, loadType);
}
});
JueKit.Type.extend(EDoc2.Department.prototype, JueKit.Collection.LinkedListNode.prototype);
还有 剩余 (1) interface 和 class的区别的问题
(2) 复习继承的概念 C++支持多重继承 JAVA和C#不支持
