码迷,mamicode.com
首页 > Windows程序 > 详细

C#out传值及函数个人练习

时间:2016-06-30 17:48:21      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.Threading.Tasks;
  6 
  7 namespace ConsoleApplication12
  8 {
  9     class Program
 10     {
 11         public void rqgs()
 12         {
 13             Console.WriteLine("请输入一个日期");
 14             try
 15             {
 16                 string a = Console.ReadLine();
 17                 DateTime b = new DateTime();
 18                 b = DateTime.Parse(a);
 19                 Console.WriteLine("输入正确");
 20             }
 21             catch
 22             {
 23                 Console.WriteLine("输入错误");
 24             }
 25             Console.ReadLine();
 26         }
 27         public void yyec(double a, double b, double c)
 28         {
 29             double sj = b * b - 4 * a * c;
 30             if (a == 0)
 31             {
 32                 Console.WriteLine("方程不是一元二次方程");
 33             }
 34             else
 35             {
 36                 if (sj >= 0)
 37                 {
 38                     double x1 = (-b + Math.Sqrt(sj)) / (2 * a);
 39                     double x2 = (-b - Math.Sqrt(sj)) / (2 * a);
 40                     if (sj > 0)
 41                     {
 42                         Console.WriteLine("方程有两个不同的实数根");
 43                         Console.WriteLine("方程的根:x1={0},x2={1}", x1, x2);
 44                     }
 45                     else
 46                     {
 47                         Console.WriteLine("方程有两个相同的实数根");
 48                         Console.WriteLine("方程的根:x1=x2=" + x1);
 49                     }
 50                 }
 51                 else
 52                 {
 53                     Console.WriteLine("方程没有实数根");
 54                 }
 55             }
 56             Console.ReadLine();
 57  
 58 
 59         }
 60         public string pdfs(string a,double b)
 61         {
 62             
 63             if (b >= 0 && b <= 100)
 64             {
 65                 if (b == 100)
 66                 {
 67                     Console.WriteLine("恭喜你,满分通过");
 68                     
 69                 }
 70                 else if (b < 100 && b >= 80)
 71                 {
 72                     Console.WriteLine( "成绩很优秀,继续保持");
 73                     
 74                 }
 75                 else if (b < 80 && b >= 60)
 76                 {
 77                     Console.WriteLine("成绩良好");
 78                     
 79                 }
 80                 else if (b < 60 && b >= 50)
 81                 {
 82                     Console.WriteLine("就差那么一点点,下次加油");
 83                    
 84                 }
 85                 else
 86                 {
 87                     Console.WriteLine("你是笨蛋吗?");
 88                     
 89                 }
 90             }
 91             string ss = Console.ReadLine();
 92             return ss;
 93 
 94         }
 95         public int pdts()
 96         {
 97             Console.WriteLine("请输入您要查询的是几月几号:");
 98             DateTime sj = new DateTime();
 99             sj = DateTime.Parse(Console.ReadLine());
100             int i = sj.DayOfYear;
101             return i;
102         }
103         public void jf(int[] x)
104         {
105             int q = x.Length;
106             for(int i=0;i<q;i++)
107             {
108                 x[i] += 10;
109             }
110  
111             
112  
113 
114 
115         }
116         public void cs(out int a)
117         {
118             a = 9;
119         }
120 
121 
122 
123         static void Main(string[] args)
124         {
125             //无参无返  输入日期判断格式
126             //Program a = new Program();
127             //a.rqgs();
128 
129             //有参无返  参数是a,b,c  一元二次方程a*x*x+b*x+c
130             //Console.WriteLine("求解方程ax*x+bx+c=0");
131             //Console.Write("请输入a=");
132             //double a = double.Parse(Console.ReadLine());
133             //Console.Write("请输入b=");
134             //double b = double.Parse(Console.ReadLine());
135             //Console.Write("请输入c=");
136             //double c = double.Parse(Console.ReadLine());
137             //Program d = new Program();
138             //d.yyec(a, b, c);
139 
140 
141             //有参有返  参数是姓名,分数  输入姓名,分数,判断分数区间100 80-100 60-80 50-60 50以下 
142             //Console.WriteLine("请输入您的姓名");
143             //string a = Console.ReadLine();
144             //Console.WriteLine("请输入你的考试成绩");
145             //double b = double.Parse(Console.ReadLine());
146             //Program c = new Program();
147 
148             //string d =c.pdfs(a, b);
149             //Console.WriteLine(d);
150             //Console.ReadLine();
151 
152             //无参有返  输入月份,日期,返回值是今年第几天
153             //Program a = new Program();
154             //int i = a.pdts();
155             //Console.WriteLine("您输入的月份是当年的第"+i+"天");
156             //Console.ReadLine();
157 
158             //out传值 形式参数:只给值,不给变量名(传值)   实际参数:将变量名传给函数(传址)
159             //out传值在传的时候仅仅是将变量名传给函数 在进行完成循环体之后,将这个变量和值一起取出
160             
161             
162             
163             //猴子吃桃
164             //int sum = 0;
165             //for (int i = 10; i >= 1; i--)
166             //{
167             //    if (i == 10)
168             //    {
169             //        sum = 1;
170             //    }
171             //    else
172             //    {
173             //        sum = 2 * (sum + 1);
174             //    }
175             //}
176             //Console.WriteLine("第一天的时候有" + sum + "个桃子");
177             //Console.ReadLine();
178 
179             //Console.WriteLine("请输入本班人数:");
180             //int a = int.Parse(Console.ReadLine());
181             //int[] cj = new int[a];
182             //for (int h = 1; h <= a; h++)
183             //{
184             //    Console.Write("请输入第" + h + "个人的成绩:");
185             //    cj[h - 1] = int.Parse(Console.ReadLine());
186 
187             //}
188             //Program x = new Program();
189             //x.jf(cj);
190             //foreach (int u in cj)
191             //{
192             //    Console.WriteLine(u);
193             //}
194             //Console.ReadLine();   
195 
196 
197 
198 
199 
200             ////split()   分离,是string类方法,string型可以.出来
201             //Console.Write("请输入姓名和学号(**-****):");
202             //string ss = Console.ReadLine();
203             //string[] sss = ss.Split(‘-‘);//以括号内字符为标准进行分割,分割后放入数组sss
204 
205             
206             
207             //Console.WriteLine("请输入一个a");
208             //int a = int.Parse(Console.ReadLine());
209             //Program s=new Program();
210             //int b = 0;
211             //s.cs(out b);
212             //Console.WriteLine(b);
213             //Console.WriteLine(a);
214             //Console.ReadLine();  ////测试out的功能。因对out理解不深,特写了一小段代码用来测试。

 

C#out传值及函数个人练习

标签:

原文地址:http://www.cnblogs.com/blueteasama/p/5630484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!