Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中检查日期时间是否在两个日期之间的方法#_C#_Datetime - Fatal编程技术网

C# 在C中检查日期时间是否在两个日期之间的方法#

C# 在C中检查日期时间是否在两个日期之间的方法#,c#,datetime,C#,Datetime,我有4个文本框(姓名、密码、重复密码和出生日期) 实际上,我有两种方法来验证名称和密码 private static void ValidarNome(string Nome) { if (Nome.Trim().Length == 0) { string msg = " O nome não pode estar em branco"; ApplicationException e = new Applic

我有4个文本框(姓名、密码、重复密码和出生日期)

实际上,我有两种方法来验证名称和密码

private static void ValidarNome(string Nome)
    {
        if (Nome.Trim().Length == 0)
        {
            string msg = " O nome não pode estar em branco";
            ApplicationException e = new ApplicationException(msg);
            throw e;
        }
    }
    private static void ValidarSenha(Int32 pw , Int32 pw2 , int check)
    {
        if (pw != pw2)
        {
            check = 1;
            string msg = " As senhas não conferem";
            ApplicationException e = new ApplicationException(msg);
            throw e;
        }
    }
但是我需要选择出生日期文本中的日期时间,并创建一个新方法来验证此日期时间是否在1960年1月1日至1990年12月31日之间,进行此验证的简单方法是什么

编辑->在用户的帮助下创建了验证日期的方法>

private static void ValidarData(DateTime d,DateTime from,DateTime to, Int32 check2, Int32 check3)
    {
        if (d < from)
        {

            check2 = 1;
            string msg = " Data de nascimento não aceita";
            ApplicationException e = new ApplicationException(msg);
            throw e;
        }
        else if (d > to)
        {
            check3 = 1;
            string msg = " Data de nascimento não aceita";
            ApplicationException e = new ApplicationException(msg);
            throw e;
        }
        else
        {
            string msg = " Cadastro Incluído";
        }
    }
private static void ValidarData(DateTime d、DateTime from、DateTime to、Int32 check2、Int32 check3)
{
如果(d到)
{
检查3=1;
string msg=“Data de nascimento não aceita”;
ApplicationException e=新的ApplicationException(msg);
投掷e;
}
其他的
{
字符串msg=“Cadastro Incluído”;
}
}
给您:

DateTime from = new DateTime(1960,1,1);
DateTime to = new DateTime(1990, 12, 31);
DateTime input = DateTime.Now;
Console.WriteLine(from <= input && input <= to); // False
input = new DateTime(1960,1,1);
Console.WriteLine(from <= input && input <= to); // True
DateTime from=新日期时间(1960,1,1);
DateTime to=新的日期时间(1990,12,31);
DateTime输入=DateTime.Now;

Console.WriteLine(来自DateTime结构重载所有标准比较运算符,因此您可以像比较数字一样对它们进行比较。

很抱歉,已搜索但未找到,这正是我所需要的,谢谢您注意,尽管对于相等性,小于几分之一秒的时间也必须相等!