using System; using System.Collections.Generic; using System.Linq;using System.Text; namespace S6hengRi { class Program { public static string[] name=new string[2];//声明字符串类型的数组 static void Main(string[] args) { #region 判断输入的日期的星座 DateTime DA = DateTime.Now;//声明日期类并且设置当前日期和时间 Console.WriteLine("请输入日期,格式为(1990-12-21):"); string date = Console.ReadLine(); bool isOK = DateTime.TryParse(date, out DA);//将字符串类型的date数据通过TryParse方法转换成DA(DateTime类型)的数据并赋给布尔类型的变量最终输出该数据 Console.WriteLine(isOK);//isOK默认值为true if (isOK) { if ((DA.Month==3&&DA.Day>=21)||(DA.Month==4&&DA.Day<=19)) { Console.WriteLine("星座:白羊座"); } } else { Console.WriteLine("输入的日期有误"); } #endregion #region 判断输入的数据是否为空 string message = Console.ReadLine(); if (string.IsNullOrWhiteSpace(message))//判断输入的数据是否为空或null { Console.WriteLine("Input is error."); } name[0] = Console.ReadLine(); if (string.IsNullOrWhiteSpace(name[0]))//判断name数组索引0的元素 { Console.WriteLine("Input is error."); } #endregion Console.ReadKey(); } } } 将字符串转换成数字 方法:Convert.ToInt32(string value,int fromBase) fromBase为进制(2,8,10,16搜索)
C#一些简单的知识
最新推荐文章于 2017-09-16 17:00:37 发布