您的位置:首页 > 编程语言 > C#

C# 知识收集录

2009-05-09 02:07 239 查看
/*

* new

*

* 1.作为运算符,用于创建对象和调用构造函数。

*

* 2.作为修饰符,用于向基类成员隐藏继承成员。

*

* 3.作为约束,用于在泛型声明中约束可能用作类型参数的参数类型。

*

*/

----------------------------------------------------------------------------------------------------------------------------

new 一个int时new运算符用于初始化其值为0

new运算符不可以重载

对于基本类型来说,使用new操作符来进行初始化的好处是,某些构造函数可以完成更优越的初始化操作,而避免了不高明的选择如:

string strA=new string('*',100);

string strB=new string(new char[]{'a','b','c'});

而不是

string strC="************************************";

----------------------------------------------------------------------------------------------------------------------------

/*

*HTML中的“定义列表标签” <DL><DT></DT><DD></DD></DL>

*/

代码:

<DL>

<DT>小标题

<DD>标题的内容说明

</DL>

显示结果:

小标题

标题的内容说明

----------------------------------------------------------------------------------------------------------------------------

/*

*Meta Tag 的简介

*/

<Title>All Products Online</title>

这虽说不是meta的一部份,但是也不可忽略,总长度不要超过85个Character (约10个字)。

<meta http-quive="content-type" content="text/html; charset=iso-8859-1">

说明网站的格式及编码方式,另外这个功能也可以拿来说明网站的名称。

<meta name="keyword" contents="关键字一, 关键字二, 关键字三, …..">

铲明整个网站的关键字,关键字间用逗点隔开,总长度最好不要超过1000个Character (约44个字)。

<meta name="description" contents="整个网站的描述….">

铲明整个网站为何吸引人的地方,可用逗点隔开,总长度最好不要超过200个Character (约15个字),若文章真的太长,可以切割成两个部分,较不重要的部分置入下一个Description。

<meta name="robots" content=" ALL, NONE, INDEX, NOINDEX, FOLLOW, NOFOLLOW">

此功能是要给搜寻引擎使用的,是要用来告诉Spider哪些网页是要去撷取的或不用去撷取的,一般都设定成All(内定值)。

-----------------------------------------------------------------------------------------------------------------------------

弹出 MSN:<a href="msnim:chat?contact=您的MSN帐号" target="_blank">

弹出QQ:tencent://message/?uin=506266157

------------------------------------------------------------------------------------------------------------------------------

/*

获取鼠标的x、y坐标

*/

<html>

<head>

</head>

<script type="text/javascript" language="javascript">

function getxy()

{

var mousex=event.x;//获取鼠标的x坐标

var mousey=event.y;//获取鼠标的y坐标

var msdiv= document.all("divms");

msdiv.innerHTML="x:"+(mousex+10)+"px<br/>y:"+(mousey-30)+"px";

msdiv.style.left=(mousex + 10)+"px";//设置div的x坐标

msdiv.style.top=(mousey -30)+"px";//设置div的y坐标

msdiv.style.display="block";

}

function hiddiv()

{

var ms= document.all("divms");

ms.style.display="none";

}

</script>

<body>

<div style="width: 200px; height: 200px; border: solid 1px #efefef; background-color: #e3e3e3;"

onmousemove="getxy();" onmouseout="hiddiv();" >

</div>

<div style="display: none; background-color: #a3b4c5; position:absolute;" id="divms">

</div>

</body>

</html>

---------------------------------------------------------------------------------------------------------

/// <summary>

/// 截取字符串(中英文字符串都适合)

/// </summary>

/// <param name="str"></param>

/// <param name="length"></param>

/// <param name="replace"></param>

/// <returns></returns>

public string getStr(string str, int length, string replace)

{

string tempStr = str;

if (Regex.Replace(tempStr, "["u4e00-"u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= length)

{

return tempStr;

}

for (int i = tempStr.Length; i >= 0; i--)

{

tempStr = tempStr.Substring(0, i);

if (Regex.Replace(tempStr, "["u4e00-"u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= length - 3)

{

return tempStr + replace;

}

}

return "";

}

--------------------------------------------------------------------------------------------------------------------------

清除cookie

HttpCookie aCookie;

string cookieName = AdsWebAppConfig.getCookiesPrefix + "UserName_Cookies";

int limit = Request.Cookies.Count;

for (int i = 0; i < limit; i++)

{

cookieName = Request.Cookies[i].Name;

aCookie = new HttpCookie(cookieName);

aCookie.Expires = DateTime.Now.AddDays(-1);

Response.Cookies.Add(aCookie);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: