Theexpression mustbe of an integral type or of a class type for which there is an unambiguousconversion to integral type. Integral promotion is performed as described inIntegral Promotions.
面试题:交换两个变量,不能声明第三个变量:
int num1 = 5;
int num2 = 6;
num1 = num1 + num2;
num2 = num1 - num2;
num1 = num1 - num2;
return(num1>num2)?num1:num2;
//三元运算符:
//分三部分:1.条件判断(true/false)2.当条件为true时。要使用的值。3.当条件为false的时候要使用的值。
intn = (11 % 2 == 0) ? 1 : 2;
方法
1、求两个数的和
2、求两(三)个数的最大值
3、求一个数是不是素数 “素数”是指除了能被1和自身整除外,不能被任何其它整数整除的自然数。
4、求一个整数数组中所有数的和
5、求数组中的最大值
=========================================================================
staticstringGetDate(stringdate)
{
stringresult =string.Empty;
for(inti = 0; i < date.Length; i++)
{
switch(date[i])
{
case'0':
result +='零';
break;
case'1':
result +='壹';
break;
case'2':
result +='贰';
break;
case'3':
result +='叁';
break;
case'4':
result +='肆';
break;
case'5':
result +='伍';
break;
case'6':
result +='陆';
break;
case'7':
result +='柒';
break;
case'8':
result +='捌';
break;
case'9':
result +='镹';
break;
default:
result += date[i];
break;
}
}
returnresult;
}
========================处理10的问题======================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[]args)
{
stringuserDate=Console.ReadLine();
userDate=ConvertDateToChinese(userDate);
Console.WriteLine(userDate);
Console.ReadKey();
}
static stringConvertDateToChinese(stringdate)
{
string[] parts =date.Split('年','月','日');
StringBuildersb= new StringBuilder();
sb.Append(ConvertYear(parts[0]));
sb.Append("年");
sb.Append(ConvertMonthDay(parts[1]));
sb.Append("月");
sb.Append(ConvertMonthDay(parts[2]));
sb.Append("日");
returnsb.ToString();
}
/// <summary>
/// 对年部分的转换
///</summary>
/// <paramname="date"></param>
/// <returns></returns>
static stringConvertYear(stringdate)
{
char[]chs=date.ToCharArray();
for (inti= 0; i<chs.Length;i++)
{
switch (chs[i])
{
case '0':
chs[i]= '零';
break;
case '1':
chs[i]= '一';
break;
case '2':
chs[i]= '二';
break;
case '3':
chs[i]= '三';
break;
case '4':
chs[i]= '四';
break;
case '5':
chs[i]= '五';
break;
case '6':
chs[i]= '六';
break;
case '7':
chs[i]= '七';
break;
case '8':
chs[i]= '八';
break;
case '9':
chs[i]= '九';
break;
}
}
return new string(chs);
}
/// <summary>
/// 对月和日的部分转换
///</summary>
/// <paramname="date"></param>
/// <returns></returns>
static stringConvertMonthDay(stringdate)
{
intnum=int.Parse(date);
//如果当前的月份或日期为10月,10日,20日,30日
if (num% 10 == 0)
{
if (num== 10)
{
return "十";
}
else
{
//返回二十,三十等。
returnNumberToChinese(num/ 10) + "十";
}
}
else if (num< 10)
{
//如果1-9月,或1-9日
returnNumberToChinese(num);
}
else if (num/ 10 == 1)
{
//如果为11月,12月,11日,12日,13日,14日......十几的情况
return"十"+NumberToChinese(num% 10);
}
else
{
//几十几的情况
returnNumberToChinese(num/ 10) + "十"+NumberToChinese(num% 10);
}
}
/// <summary>
/// 将0-9的数字转换为char字符
///</summary>
/// <paramname="n"></param>
/// <returns></returns>
static stringNumberToChinese(intn)
{
stringch=string.Empty;
switch (n)
{
case 0:
ch= "零";
break;
case 1:
ch= "一";
break;
case 2:
ch= "二";
break;
case 3:
ch= "三";
break;
case 4:
ch= "四";
break;
case 5:
ch= "五";
break;
case 6:
ch= "六";
break;
case 7:
ch= "七";
break;
case 8:
ch= "八";
break;
case 9:
ch= "九";
break;
}
returnch;
}
}
}
二维数组:
int[,] aa = new int[2, 3];
交错数组:
int[][] nn = new int[10][];