C#学习笔记(2)

简介: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using Syst
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace demo2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
             Random r = new Random();				// 实例化Random类
            int[] array = new int[3] { r.Next(100), r.Next(100), r.Next(100) };
            textBox1.Text = "随机生成的3个数为:"+
			array[0].ToString()+","+array[1].ToString()+","+array[2].ToString()+"\r\n";
            int Max;
            Sort S = new Sort();
            Max = S.Sort_1(array[0],array[1],array[2]);
            textBox1.Text += "值参数方法,最大值为:" + Max.ToString() + "\r\n";


            S.Sort_2(ref array[0],ref array[1],ref array[2]);
            textBox1.Text += "引用参数方法,最大值为:" + array[2].ToString() + "\r\n";


            S.Sort_3(array[0],array[1],array[2],out Max);
            textBox1.Text += "输出参数方法,最大值为:" + Max.ToString() + "\r\n";


            S.Sort_4(out Max, array);
            textBox1.Text += "参数数组方法,最大值为:" + Max.ToString();
        }
    }
    class Sort									// 声明一个类Sort
    {
        public int Sort_1(int x, int y, int z)     			// 值参数方法
        {
            int tmp;                              	// tmp是方法Sort_1的局部变量
            // 将x,y,z按从小到大排序
            if (x > y) { tmp = x; x = y; y = tmp; }
            if (x > z) { tmp = x; x = z; z = tmp; }
            if (y > z) { tmp = y; y = z; z = tmp; }
            return z;							// 返回最大值z
        }
        public void Sort_2(ref int x, ref int y, ref int z) 		// 引用参数方法
        {
            int tmp;                            	   	// tmp是方法Sort_2的局部变量
            // 将x,y,z按从小到大排序
            if (x > y) { tmp = x; x = y; y = tmp; }
            if (x > z) { tmp = x; x = z; z = tmp; }
            if (y > z) { tmp = y; y = z; z = tmp; }
        }
        public void Sort_3(int x, int y, int z, out int max)	// 输出参数方法
        {
            int tmp;                            		// tmp是方法Sort_3的局部变量
            // 将x,y,z按从小到大排序
            if (x > y) { tmp = x; x = y; y = tmp; }
            if (x > z) { tmp = x; x = z; z = tmp; }
            if (y > z) { tmp = y; y = z; z = tmp; }
            max = z; 							// 最大值z赋给参数max
        }
        public void Sort_4(out int max, params int[] a) 		// 参数数组方法               
        {
            max = a[0];
            for (int i = 1; i < a.Length; i++)
            { if (a[i] > max) max = a[i]; }
        }
   }
}


目录
相关文章
|
C#
C#中的数组型参数学习笔记
C#中的数组型参数学习笔记
295 1
halcon联合c#、WPF学习笔记三(dispatcherTimer实时相机显示)
halcon联合c#、WPF学习笔记三(dispatcherTimer实时相机显示)
1258 2
halcon联合c#、WPF学习笔记三(dispatcherTimer实时相机显示)
|
C# C++
halcon联合c#、WPF学习笔记一(WPF配置halcon)
halcon联合c#、WPF学习笔记一(WPF配置halcon)
2361 1
|
测试技术 持续交付 C#
C#程序基础开发入门学习笔记
C#是一种现代的、面向对象的编程语言,广泛应用于Windows应用程序开发、游戏开发(尤其是Unity引擎)、Web应用程序以及跨平台应用等。
557 0
halcon联合c#、WPF学习笔记二(简单案例)
halcon联合c#、WPF学习笔记二(简单案例)
2114 0
|
C# C语言
C#学习笔记22: 面向对象编程入门精讲(下)
C#学习笔记22: 面向对象编程入门精讲
C#学习笔记22: 面向对象编程入门精讲(下)
c#编程:事件delegate学习笔记-3
c#编程:事件delegate学习笔记-3
316 0
|
缓存 开发框架 运维
C#好代码学习笔记(1):文件操作、 读取文件、Debug/Trace类、Conditional条件编译、CLS
C#好代码学习笔记(1):文件操作、 读取文件、Debug/Trace类、Conditional条件编译、CLS
470 0
|
开发框架 并行计算 .NET
改善C#程序的157个建议——建议84学习笔记:使用PLINQ
改善C#程序的157个建议——建议84学习笔记:使用PLINQ
311 0