lwj_C#_类的属性,方法参数 举例习题

//    public class Hero
//    {
//        public string name;
//        //字段
//        private int age;
//        //属性  //属性里面不要使用属性本身;
//        public int Age{
//            get{ 
//                return age;
//            }
//            set{   //可以在这里面操作 分支语句if
//                age = value;//只有set里面有value;
//            }
//        }
//        public  void  Change(int[]array){
//            array [0] = 4;
//        }
//
//        //排序
//        //冒泡排序
//        public void Sort(int[]array){
//            for (int i = 0; i < array .Length - 1; i++) {
//                for (int j = 0; j < array.Length - i - 1; j++) {
//                    if (array[j] > array[j + 1]) {
//                        int temp = array [j];
//                        array[j] = array[j + 1];
//                        array[j + 1] = temp;
//                    }
//                }
//            }
//        }
//
//        //选择排序
//        public void Sort1(int[]array){
//            for (int i = 0; i < array.Length - 1; i++) {
//                int min = array [i];
//                int minIdex = 0;
//                for (int j = i + 1; j < array.Length; j++) {
//                    if (min > array[j]) {
//                        min = array [j];
//                        minIdex = j;
//                    }
//                }
//                array[minIdex] = array [i];
//                array[i] = min;
//            }
//        }
//    
//        //方法参数
//        //引用参数 ref  调用时也要加ref; 传递前要赋值 初始值;
//        public void Swap(ref int []x, ref int[] y){
//            int[] temp= x;
//            x = y;
//            y = temp;
//
//
//        }
//
//        //输出参数 out  out传递前可以没有值; 可以返回x y;
//        public int Cal(int a ,int b, out int x, out int y){
//            x = a + b;
//            y = a - b;
//            return x * y;
//        }
//
//        //params 必须时一维数组 输入任意个数的参数;
//        public float Avg(params int[] array){
//            int sum = 0;
//            foreach (int a in array) {
//                sum += a;
//            } 
//            return sum / array.Length;
//        }
//
//        //三个数从小到大排序
//        public void Max(ref int a, ref int b, ref int c){
//            int max = (a > b ? a : b) > c ? (a > b ? a : b) : c;
//            int min = (a < b ? a : b) < c ? (a < b ? a : b) : c;
//            int mid = (a + b + c) - max - min;
//            a = min; b = mid; c = max;
//            //方法二
////            if (a < b) {
////                int temp = a;
////                a = b;
////                b = temp;
////            }
////            if (a > c) {
////                int temp = a;
////                a = c;
////                c = temp;
////            }
////            if (b > c) {
////                int temp = b;
////                b = c;
////                c = temp;
////            }
//
//        }
//
//        //作业求和 数组奇数位为负数;
//        public int Sum(params int [] array){
//            int sum = 0;
//            for (int i = 0; i < array.Length; i++) {
//                if (i % 2 != 0) {
//                    array [i] = -array [i];
//                } 
//                sum += array [i];
//            }
//            return sum;
//        }
//    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值