C# - 习题04_分析代码写出结果i1、i2、c.i、str、c.str

  • 时间:2017-08-23 整理:byzqy

题目:分析如下代码,写出程序输出结果。

文件:Class1.cs

using System;

namespace Interview3
{
    class Class1
    {
        private string str = "Class1.str";
        private int i = 0;
        static void StringConvert(string str)
        {
            str ="string being converted.";
        }
        static void StringConvert(Class1 c)
        {
            c.str ="string being converted.";
        }
        static void Add(int i)
        {
            i++;
        }
        static void AddWithRef(ref int i)
        {
            i++;
        }
        static void Main()
        {
            int i1 = 10;
            int i2 = 20;
            string str = "str";
            Class1 c = new Class1();
            Add(i1);
            AddWithRef(ref i2);
            Add(c.i);
            StringConvert(str);
            StringConvert(c);
            Console.WriteLine(i1);
            Console.WriteLine(i2);
            Console.WriteLine(c.i);
            Console.WriteLine(str);
            Console.WriteLine(c.str);

            Console.ReadKey();
        }
    }
}

输出结果:

 

转载于:https://www.cnblogs.com/jswl/p/7420783.html

1. 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。 答:public class MainClass { public static void Main() { Console.WriteLine(Foo(30)); } public static int Foo(int i) { if (i <= 0) return 0; else if(i > 0 && i <= 2) return 1; else return Foo(i -1) + Foo(i - 2); } } 2.C#中的委托是什么?事件是不是一种委托? 答 :委托可以把一个方法作为参数代入另一个方法。 委托可以理解为指向一个函数的引用。 是,是一种特殊的委托。 3.override与重载的区别 答 :overrider与重载的区别。重载是方法的名称相同。参数或参数类型不同,进行多次重载以适应不同的需要。 Overrider是进行基类中函数的重。为了适应需要。 4.如果在一个B/S结构的系统中需要传递变量值,但是又不能使用Session、Cookie、Application,您有几种方法进行处理? 答 : this.Server.Transfer 5.请编程遍历页面上所有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 ; } } 6.请编程实现一个冒泡排序算法? 答: int [] array = new int[] {1,3,5,8,0,2,3,10,8,10}; 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 ; } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值