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



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值