130道c#面试题
1. 简述 private、 protected、 public、 internal 修饰符的访问权限。
答 . private : 私有成员, 在类的内部才可以访问。
protected : 保护成员,该类内部和继承类中可以访问。
public : 公共成员,完全公开,没有访问限制。
internal: 在同一命名空间内可以访问。
2 .列举ASP.NET 页面之间传递值的几种方式。
答. 1.使用QueryString, 如....?id=1; response. Redirect()....
2.使用Session变量 3.使用Server.Transfer
3. 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少,
用递归算法实现 答:1public class MainClass 2 public static void Main()
{ 3Console.WriteLine(Foo(30)); 4 public static int Foo(int i)
{ 5 if (i <= 0) return 0; 6else if(i > 0 && i <= 2) 7return 1;
else return Foo(i -1) + Foo(i - 2);
4.C#中的委托是什么?事件是不是一种委托?
答 : 委托可以把一个方法作为参数代入另一个方法。委托可以理解为指向一个函数的引用。
是,是一种特殊的委托
5.override与重载的区别
答 :override 与重载的区别。重载是方法的名称相同。参数或参数类型不同,进行多次重载以适应不同的需要Override 是进行基类中函数的重写。为了适应需要。
6.如果在一个B/S结构的系统中需要传递变量值,但是又不能使用Session、Cookie、Application,您有几种方法进行处理?
答 : this.Server.Transfer
7.请编程遍历页面上所有TextBox控件并给它赋值为string.Empty?
答:foreach (System.Windows.Forms.Control control in this.Controls)
{if (control is System.Windows.Forms.TextBox)
{System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ;
tb.Text = String.Empty ;
8.请编程实现一个冒泡排序算法?
答:int [] array = new int int temp = 0 ;for (int i = 0 ; i < array.Length - 1 ; i++)for (int j = i + 1 ; j < array.Length ; j++)if (array[j] < array[i])
{temp = array[i] ;array[i] = array[j] ;array[j] = temp ;
9.描述一下C#中索引器的实现过程,是否只能根据数字进行索引?
答:不是。可以
相关文档:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
//sqlserver身份验证
//string sqlconn = "ser ......
一、Access从Excel中导入数据
1.用到的Excel表的格式及内容
实现
OleDbConnection con = new OleDbConnection();
try
{
OpenFileDialog openFile = new OpenFileDialog();//打开文件对话框。
openFile.Filter = ("Excel 文件(*.xls)|*.xls") ......
public string WriteXML(string[] values, int flag)
{
//如果flag==0则为第一次运行需要初始化XML文件
if (flag == 0)
{
//生在随机文件名
string dateName = System.DateTime.Now.ToString("yyyyMMddHHmmss");
......
一.类与结构的示例比较:
结构示例:
public struct Person
{
string Name;
int height;
int weight
public bool overWeight()
{
//implement something
}
}
类示例:
public class TestTime
{
int hours;
int minutes;
int seconds;
public void passtime()
{
//implementation ......