.NET面试题库(转载)
posted @ 2011-10-17 19:28 乔乔lovefreedom 阅读(81) 评论(0) 编辑
2011年10月17日 #
posted @ 2011-10-17 19:28 乔乔lovefreedom 阅读(81) 评论(0) 编辑
2011年9月7日 #
静态页面
<head runat="server">
<title></title>
<script src="jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function changeCity() {
var c = $("#Select1").val();
var bei = $("#Select2");
var tian = $("#Select3");
if (c == "1") {
bei.show();
tian.hide();
}
if (c == "2") {
bei.hide();
tian.show();
}
}
</script>
</head>
<body onload="changeCity();">
<form id="form1" runat="server">
<div>
城市:<select id="Select1" onchange="changeCity();">
<option value="1">北京</option>
<option value="2">天津</option>
</select>
城区:
<select id="Select2">
<option value="1">朝阳区</option>
<option value="2">海淀区</option>
</select>
<select id="Select3" >
<option value="1">和平区</option>
<option value="2">塘沽区</option>
</select>
</div>
</form>
</body>
-----------------------------------------------------------------------------
支持后台数据
<head runat="server">
<title></title>
<script src="jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function get() {
var dataParamter = "city=" + $("#city").val(); ;
$.ajax({
type: "POST",
dataType: "xml",
url: "Cityaaaa.ashx",
data: dataParamter,
success: function (data) {
var qu = $("#sel_b"); var op = "";
var nodeList = $("node", data);
if (nodeList.length > 0) {
nodeList.each(function (i) {
var nodeID = $(this).children("ID").text();
var typeName = $(this).children("name").text();
op += "<option value='" + nodeID + "'>" + typeName + "</option>";
});
}
qu.html(op);
}
});
}
</script>
</head>
<body onload="get();">
<form id="form1" runat="server">
<div>
城市:<select id="city" onchange="get();">
<option value="1">北京</option>
<option value="2">天津</option>
</select>
城区:
<select id="sel_b">
</select>
<br />
------------------------------------------------------------------------------
<br />
</div>
</form>
</body>
public class Cityaaaa : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
StringBuilder returnStr = new StringBuilder("<nodes>");
if (!string.IsNullOrEmpty(context.Request["city"]))
{
int level;
if (int.TryParse(context.Request["city"], out level))
{
if (string.IsNullOrEmpty(context.Request["city"]) == false)
{
int type;
if (int.TryParse(context.Request["city"], out type))
{
IList<City> codeTypeList = this.GetData(type);
if (codeTypeList != null && codeTypeList.Count > 0)
{
string listStr = GetCodeType(codeTypeList);
if (string.IsNullOrEmpty(listStr) == false)
{
returnStr.Append(listStr);
}
}
}
}
}
}
returnStr.Append("</nodes>");
context.Response.ContentType = "text/xml";
context.Response.Write(returnStr.ToString());
}
//组建代码扩展信息XML节点串
private string GetCodeType(IList<City> typeList)
{
StringBuilder codeSb = new StringBuilder();
if (typeList != null && typeList.Count > 0)
{
foreach (City code in typeList)
{
codeSb.Append("<node>");
codeSb.Append("<ID>" + code.ID + "</ID>");
codeSb.Append("<name>" + code.Name + "</name>");
codeSb.Append("</node>");
}
}
return codeSb.ToString();
}
private IList<City> GetData(int flag)
{
IList<City> list = new List<City>();
switch (flag)
{
case 1:
list.Add(new City() { ID = 1, Name = "东城区" });
list.Add(new City() { ID = 2, Name = "xi城区" });
list.Add(new City() { ID = 3, Name = "bei城区" });
list.Add(new City() { ID = 4, Name = "nan城区" });
break;
case 2:
list.Add(new City() { ID = 1, Name = "111" });
list.Add(new City() { ID = 2, Name = "xi222城区" });
list.Add(new City() { ID = 3, Name = "bei3333城区" });
list.Add(new City() { ID = 4, Name = "nan4444城区" });
break;
default:
break;
}
return list;
}
public bool IsReusable
{
get
{
return false;
}
}
}
。cs文件中的
posted @ 2011-09-07 01:42 乔乔lovefreedom 阅读(14) 评论(0) 编辑
create table #tmp
(
name nvarchar(50),
[subject] nvarchar(50),
grade float
)
insert into #tmp values('张三' ,'语文',90)
insert into #tmp values('张三' ,'数学',80)
insert into #tmp values('张三' ,'英语',75)
insert into #tmp values('李四' ,'语文',75)
insert into #tmp values('李四' ,'数学',60)
insert into #tmp values('李四' ,'英语',85)
insert into #tmp values('王五' ,'语文',85)
insert into #tmp values('王五' ,'数学',77)
insert into #tmp values('王五' ,'英语',99)
select * from #tmp;
select name as 姓名,
AVG(case when [subject]='语文' then grade end) as 语文,
AVG(case when [subject]='数学' then grade end) as 数学,
AVG(case when [subject]='英语' then grade end) as 英语
from #tmp
group by #tmp.name
create table #tmp2 --添加物理、化学
(
姓名 nvarchar(50),
物理 float,
化学 float
)
insert into #tmp2 values('张三' ,75,80)
insert into #tmp2 values('李四' ,95,85)
insert into #tmp2 values('王五' ,90,85)
select * from #tmp2;
select a.姓名,a.语文,a.数学,a.英语,b.物理,b.化学 from (
select name as 姓名,
AVG(case when [subject]='语文' then grade end) as 语文,
AVG(case when [subject]='数学' then grade end) as 数学,
AVG(case when [subject]='英语' then grade end) as 英语
from #tmp
group by #tmp.name) a left join #tmp2 b on a.姓名=b.姓名
posted @ 2011-09-07 00:46 乔乔lovefreedom 阅读(13) 评论(0) 编辑
2011年9月6日 #
// 可以接受若干参数的委托
public delegate double Method( params int[] numbers);
public class Demo
{
public double Times( params int[] numbers)
{
double result = 1;
foreach (int i in numbers)
result *= i;
return result;
}
public double Div(params int[] numbers)
{
if (numbers == null || numbers.Length == 0)
throw new InvalidOperationException("参数错误");
if (numbers.Length == 1)
return numbers[0];
double first = numbers[0];
int length = numbers.Length;
for (int i = 1; i < length; i++)
{
int x = numbers[i];
if (x == 0)
throw new InvalidOperationException("错误的参数");
first /= x;
}
return first;
}
}
public class Calculator
{
public Method Times;
public Method Div;
public Calculator()
{
}
public double MyTimes(params int[] numbers)
{
return this.Times(numbers);
}
public double MyDiv(params int[] numbers)
{
return this.Div(numbers);
}
}
class Program
{
static void Main(string[] args)
{
// 装配
Calculator calculator = new Calculator();
Demo demo = new Demo();
calculator.Times = demo.Times;
calculator.Div = demo.Div;
// 使用计算器
double r = calculator.MyTimes(1, 2, 3, 4);
Console.WriteLine(r);
double r2 = calculator.MyDiv(12, 2, 3);
Console.WriteLine(r2);
}}
posted @ 2011-09-06 13:49 乔乔lovefreedom 阅读(9) 评论(0) 编辑
2011年5月5日 #
posted @ 2011-05-05 10:11 乔乔lovefreedom 阅读(172) 评论(0) 编辑
2011年3月16日 #
给你1000个苹果,给你10个箱子,苹果可以往箱子里面随便放,我向你要苹果的时候,我肯定是要1000个以内的(含1000个),你必须给我箱子,箱子里面存放着我要的苹果,给我的箱子数目任意,请问,这10个箱子中苹果应该怎么放?
答案:大学的递归算法和数学归纳法思想,我们必须联想到递推的含义,要解决大的问题,就必须在小的问题上进行找规律,所以我们从最基本的做起,我要一个苹果,你必须在某个箱子只能放入一个苹果,我要两个,此时面临的选择是你可以两个箱子各放一个苹果,也可以在某一个箱子放入两个苹果,但是你要考虑到我们只有10个箱子,所以必须要以最小的次数来解决问题,我们选择在某个箱子放入两个苹果,这样,即便是我要三个苹果的时候,你就可以把两个箱子给我,因为两个箱子里面一共装了3个苹果,当我要四个苹果的时候,你不满足,此时你面临的选择,在某个箱子放入一个苹果,在某个箱子放入两个苹果,或者在某个箱子放入四个苹果,因为我们要满足更大的数目,所以我们要在某个箱子放入四个苹果,以此类推,我们放入的苹果为8,16,32,64,128,256,此时要注意,只剩下最后一堆的苹果了,我们算出,现在已经放入箱子的苹果数目为511个,所以最后我们只能放入1000-511 = 489个,此题目的规律类似于斐波那契数列,前面的苹果数目只能满足前面苹果数目相加起来的情况,所以啊,最后一个元素不用考虑是否满足,而是一定满足的,所以最后一个必须为489个,这也检验了一个人是否细心,所以我们必须要学会谨慎的思维,而不能浮躁!
posted @ 2011-03-16 20:08 乔乔lovefreedom 阅读(178) 评论(1) 编辑
C#中equal与==的区别 收藏
对于值类型,如果对象的值相等,则相等运算符 (==) 返回 true,否则返回 false。对于string 以外的引用类型,如果两个对象引用同一个对象,则 == 返回 true。对于 string 类型,== 比较字符串的值。
==操作比较的是两个变量的值是否相等。
equals()方法比较的是两个对象的内容是否一致.==也就是比较引用类型是否是对同一个对象的引用。
例子:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string a = new string(new char[] { 'h', 'e', 'l', 'l', 'o' });
string b = new string(new char[] { 'h', 'e', 'l', 'l', 'o' });
Console.WriteLine(a == b);
Console.WriteLine(a.Equals(b));
object g = a;
object h = b;
Console.WriteLine(g == h);
Console.WriteLine(g.Equals(h));
Person p1 = new Person("jia");
Person p2 = new Person("jia");
Console.WriteLine(p1 == p2);
Console.WriteLine(p1.Equals(p2));
Person p3 = new Person("jia");
Person p4 = p3;
Console.WriteLine(p3 == p4);
Console.WriteLine(p3.Equals(p4));
Console.ReadLine();
}
}
}
输出
true,true,false,true,false,false,true,true。
posted @ 2011-03-16 15:34 乔乔lovefreedom 阅读(510) 评论(0) 编辑
2011年2月14日 #
posted @ 2011-02-14 14:34 乔乔lovefreedom 阅读(341) 评论(1) 编辑
2011年1月28日 #
posted @ 2011-01-28 18:53 乔乔lovefreedom 阅读(211) 评论(0) 编辑
2011年1月27日 #
posted @ 2011-01-27 13:58 乔乔lovefreedom 阅读(73) 评论(0) 编辑