标签:for void ons 值类型 表达 修改 ++ 相互 switch
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一串文字:");
String str = Console.ReadLine();
foreach (char item in str)
{
if (char.IsWhiteSpace(item))
{
Console.WriteLine();
}else{
Console.Write(item);
}
}
Console.ReadKey();
}
}
}
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 表达式 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 for (int i = 1; i < 11; i++) 14 { 15 if (i % 4 == 0) 16 { 17 break; 18 } 19 20 Console.Write(i); 21 } 22 Console.ReadLine(); 23 } 24 } 25 }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 表达式 { class Program { static void Main(string[] args) { Console.WriteLine("50以内的奇数:"); for (int i = 1; i <=50; i++) { if (i % 2 == 0) { continue; } Console.Write(i+"\t"); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 表达式 { class Program { static void Main(string[] args) { while (true) { Console.WriteLine("请输入三个整数按回车键确认每个数的输入:"); int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); int c = int.Parse(Console.ReadLine()); Console.WriteLine("平均数为{0}", average(a, b, c)); } Console.ReadLine(); } static double average(int A,int B,int C) { return (A + B + C) / 3; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 表达式 { class Program { static void Main(string[] args) { while (true) { Console.WriteLine("请输入三个整数按回车键确认每个数的输入:"); int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); int c = int.Parse(Console.ReadLine()); average(a,b,c); } Console.ReadLine(); } static void average(int A,int B,int C) { Console.WriteLine("平均数为{0}", (A+B+C)/3); return; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 表达式 { class Program { static void Main(string[] args) { //5的阶层等于? Console.WriteLine("5的阶乘等于?根据以下选项选择正确答案,回车键确认!"); Console.WriteLine("1. 5!=5\n2. 5!=10\n3. 5!=20\n4. 5!=60"); //用户的判定 //标识符标志内容 error: { Console.WriteLine("您回答错了!"); } int option=int.Parse(Console.ReadLine()); switch(option){ case 1: case 2: case 3: goto error; case 4: goto right; default : Console.WriteLine("选项不存在,请重新选择"); //break; goto end; } right: { Console.WriteLine("恭喜答对了"); } end: ; //end: { } Console.ReadLine(); } } }
限制转换与隐式转换
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 表达式 { class Program { static void Main(string[] args) { int x = 98; char y = ‘a‘; x = y; y = (char)x;//强制转换 //字符型‘a‘隐式转换为int型 Console.WriteLine(x);//输出97 Console.WriteLine(y); Console.ReadLine(); } } }
字符串和整型数据相互转换
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 表达式 { class Program { static void Main(string[] args) { /*int x = 12222; string str = "abcd"; str = Convert.ToString(x); Console.WriteLine(str);*/ int x = 12222; string str = "122222"; x = Convert.ToInt32(str); Console.WriteLine(x); Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 表达式 { class Program { static void Main(string[] args) { /*int x = 12222; string str = "abcd"; str = Convert.ToString(x); Console.WriteLine(str);*/ int x = 12222; string str = "122222"; //x = Convert.ToInt32(str); str = x.ToString();//值类型转换为字符串类型,可以这样用 Console.WriteLine(x); Console.Read(); } } }
标签:for void ons 值类型 表达 修改 ++ 相互 switch
原文地址:http://www.cnblogs.com/qikeyishu/p/7496065.html