C#一些简单的知识
2017-03-22 20:00
253 查看
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#和VB.NET。当你想测试一些简单的代码的时候可以使用。
- c#对MSSQL一些简单的操作
- C#中如何实现AVI视频的播放并且需要在播放视频的同时在视频上进行一些简单线条的绘制?
- c#中的一些基本知识 - 待补充
- 关于C#中的Delegate的一些知识
- 一些C#的简单实例
- 简单讲解一些linux的小知识吧
- C#实现的一些音频,视频,简单动画效果
- C#入门不简单(上网找beginning c# objects时看到的一些话,很有同感)
- C#的一些基础知识补习 一
- 一些C#相关知识整理
- C#一些基本知识
- StringBuilder 的一些小知识(C#)
- C#与Asp.net一些简单控件的区别(一)
- c#开发的一些简单技巧
- C#开发环境(IDE)中的一些知识
- [温故知新]c#的一些基础知识
- C# 获取一些简单的本机信息
- 编译预处理一些知识简单总结
- C#的一些基础知识补习 二