C# out
来源:互联网 发布:dota2网络连接超时 编辑:程序博客网 时间:2024/06/08 09:37
out参数侧重于在函数中返回多个值
out 参数要求必须在方法的内部为其赋值
ref侧重对参数的改变;out侧重对参数的赋值,侧重输出多个参数。ref实参要求有初始值,out实参不要求有初始值
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace out参数的使用{ class Program { static void Main(string[] args) { //out参数侧重于在函数中返回多个值 //out 参数要求必须在方法的内部为其赋值 //int n; //string s; //bool b = Test(out n, out s); //Console.WriteLine(b); //Console.WriteLine(n); //Console.WriteLine(s); //Console.ReadKey(); //登陆 //1、在Main函数中提示用户输入用户名和密码 //2、将用户输入的用户民和密码传给你写的IsLogin进行判断 //3、如果登陆成功,则返回true,并且返回"登陆成功"; //4、如果登陆失败,则返回false,并且返回 "到底哪错了"; //bool Is Login() //while (true) //{ // Console.WriteLine("请输入用户名"); // string name = Console.ReadLine(); // Console.WriteLine("请输入密码"); // string pwd = Console.ReadLine(); // string msg; // bool b = IsLogin(name, pwd, out msg); // Console.WriteLine("登陆结果{0}", b); // Console.WriteLine("登陆信息{0}", msg); // Console.ReadKey(); //} //可变参数params,且后面不允许有其他形参 Test2("zhangsan", 1, 2, 3); } static void Test2(string name, params int[] score) { } static void Change(ref int n1, ref int n2) { int temp = n1; n1 = n2; n2 = temp; } static bool IsLogin(string name, string pwd, out string msg) { if (name == "admin" && pwd == "123123") { msg = "登陆成功"; return true; } else if (name == "admin") { msg = "密码错误"; return false; } else if (pwd == "123123") { msg = "用户名错误"; return false; } else { msg = "未知错误!!!!"; return false; } } static bool Test(out int number, out string res) { //返回一个bool int string number = 10; res = "张三"; return true; } }}
阅读全文
0 0
- C# out
- C# ref and out
- c# out ref 使用
- C# out关键字
- 学习笔记:c# out
- C# out关键字
- C#中的out string
- C# OUT 参数
- C# params,ref,out
- c#中的ref out
- C# ref out
- C# ref out
- C# out关键字
- C# out关键字
- C# out修饰符
- C# 参数关键字out
- C# ref/out 關鍵字與傳遞參考型別參數
- C# out 的用法
- 分割整数
- 鼠标或者触屏滑动旋转角度查看人物效果(类似王者荣耀里选择人物查看)
- 输出乘法口诀表
- 架构设计:负载均衡层设计方案1
- 矩阵键盘
- C# out
- spring大致框架流程
- softmax回归模型
- FPGA基础实验:用计数器读取ROM数据产生信号波形(直接数字频率合成DDS)
- 计算机硬件--笔记
- 内存管理
- C语言位运算符
- Eclipse Maven "Create a simple project" 没有web.xml文件
- t-分布邻域嵌入算法(t-SNE algorithm)简单理解