价值不在预期范围内 [英] value doesn't fall within the expected range

查看:96
本文介绍了价值不在预期范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在开发c#app,我选择了一个来自此消息的消息



value不属于预期范围

此错误的实例

显示调用堆栈

解决方案

我假设错误发生在某处:

  string  iii =   .bak; 
string xxx = dateTimePicker4.Text;
string y = Convert.ToString(i);
string format =( yyyy-MM -dd);
DateTime f = Convert.ToDateTime(xxx);
string yy = f.ToString(format);



对于初学者,不要使用DateTimePicker.Text - 它有一个Value属性,可以直接返回DateTime,所以你不需要进行任何转换。

你不能使用y中的值,所以你可以使用不需要分配它。

你不需要围绕字符串文字的括号

  string  iii =   .bak; 
string y;
string format = yyyy-MM- DD;
DateTime f = dateTimePicker4.Value;
string yy = f.ToString(format);



其实我会简化这个一点:

  string  iii =   .bak; 
string y;
string yy = dateTimePicker4.Value.ToString( yyyy-MM-dd);

我也会更改名称:

  string  backupExt =   .bak; 
string temp;
string dateFormatted = dateTimePicker4.Value.ToString( YYYY-MM-DD);


Hello,
I''m developing c# app, and one I choose form this message comes out

value doesn''t fall within the expected range
instances of this error
show call stack

解决方案

I assume the error is happening here somewhere:

string iii=".bak";
string xxx = dateTimePicker4.Text;
string y = Convert.ToString(i);
string format = ("yyyy-MM-dd");
DateTime f = Convert.ToDateTime(xxx);
string yy = f.ToString(format);


For starters, don''t use DateTimePicker.Text - it has a Value property which returns a DateTime directly, so you do not need to do any conversion.
You don''t use the value in "y", so ythere is no need to assign it.
You don''t need brackets round a string literal

string iii=".bak";
string y;
string format = "yyyy-MM-dd";
DateTime f = dateTimePicker4.Value;
string yy = f.ToString(format);


In fact, I would simplify this a bit:

string iii=".bak";
string y;
string yy = dateTimePicker4.Value.ToString("yyyy-MM-dd");

And I would change the names as well:

string backupExt = ".bak";
string temp;
string dateFormatted = dateTimePicker4.Value.ToString("yyyy-MM-dd");


这篇关于价值不在预期范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆