C#经典面试题及答案

上一篇 / 下一篇  2008-08-14 11:38:15

    现在收集些常见面试题:

   将比较常见的C#面试题分布出来供有需求的朋友参考,本文章会不断更新。如果有好的面试题不妨给我留言,我来完善。
最好是有答案的。


  1:委托和事件
    
 //事件类
    public class EventClass
    
{
        
public void display(object sender, System.EventArgs e)
        
{
            Console.WriteLine(
"This is the Event Class");
            Console.ReadLine();
        }

    }

    
//调用类
    class InvokeClass
    
{
        
//声明代理对象,注意参数
        public delegate void delegateobj(object sender, System.EventArgs e);
        
//声明事件对象 
        private event delegateobj obj;
        
//声明要调用的事件类对象
        private EventClass ec;

        
public InvokeClass()
        
{
            ec 
= new EventClass();
            
//添加事件对象到事件队列中,参数为要调用的事件
            this.obj += new delegateobj(ec.display);
        }

        
//调用delegate对象触发事件
        protected void OnObj(System.EventArgs e)
        
{
            
if (this.obj != null)
            
{
                obj(
this, e);
            }

        }

        
public void RaiseEvent()
        
{
            EventArgs e 
= new EventArgs();
            OnObj(e);
        }

        
static void Main(string[] args)
        
{
            InvokeClass ic 
= new InvokeClass();
            Console.WriteLine(
"Please input a string");
            
string input = Console.ReadLine();
            
if (input.Equals(""))
            
{
                Console.WriteLine(
"Sorry,you don't input anything");
            }

            
else
            
{
                
//触发事件
                ic.RaiseEvent();
            }

        }

    }
      
     2:遍历页面中所有的TextBox,交将值设置成"a"
    
for (int j = 0; j < this.Controls.Count; j++)
            
{
                
foreach (object o in Page.Controls[j].Controls)
                
{
                   
                    
if (o is TextBox)
                    
{
                        TextBox txt 
= (System.Web.UI.WebControls.TextBox)o;
                        txt.Text 
= "A";
                    }

                   
                }

            }
       
       3  常用排序算法
        
 /// <summary>
        
/// /冒泡排序
        
/// </summary>

        private void BubbleSort()
        
{
            
//冒泡排序
            int[] list = new int[511112223854-5655 };//初始化数组
            int i, j, temp;
            
for (j = 1; j < list.Length; j++)
            
{
                
for (i = 0; i < list.Length - j; i++)
                
{
                    
if (list[i] > list[i + 1])
                    
{
                        temp 
= list[i];
                        list[i] 
= list[i + 1];
                        list[i 
+ 1= temp;
                    }

                }


            }

            

        }

        
/// <summary>
        
/// 选择排序
        
/// </summary>

        private void SelectSort()
        
{
            
//选择排序
            int[] a = new int[511112223854-5655 };//初始化数组
            int min, min_k;//定义最小数,和最小数的下标
            for (int i = 0; i < 5; i++)
            
{
                min 
= a[i];//将当前循环的数设置成最小数
                min_k = i;
                
for (int j = i + 1; j < 5; j++)
                
{

                    
if (a[j] < min)
                    
{
                        min 
=

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-11-22  
      1
2345678
9101112131415
16171819202122
23242526272829
30      

数据统计

  • 访问量: 7200
  • 日志数: 54
  • 建立时间: 2007-08-01
  • 更新时间: 2008-08-14

RSS订阅

Open Toolbar