C#一些简单的知识

 
 

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搜索)


 
发布了14 篇原创文章 · 获赞 10 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_36545099/article/details/64926920