English 中文(简体)
未用当地变数“总数” ......
原标题:use of unassigned local variable `total`

我想有一份所有间隔的总和,但我写这部法典,我有一处错误,称:使用未经签名的当地变量<条码>(<>全程/代码>?

enter TimeSpan total;
foreach (var grp in query)
{
  TimeSpan interval = TimeSpan.FromMinutes(grp.Minuut); 
  TimeSpan intervalH = TimeSpan.FromHours(grp.Sum);

  interval = interval + intervalH;
  total += interval;
  string timeInterval = interval.ToString();   
  dataGridView2.Rows.Add(i++, grp.Id, grp.Sum, grp.Minuut,timeInterval);
}
问题回答

开始:

TimeSpan total = TimeSpan.Zero;

取消无价值变量是毫无意义的。 因此,这是汇编错误的唯一自然之处。

虽然fields已初步形成0,但必须先将当地变量分配到它们一读之前。 在您的节目 Total += interval; 改为 Total,以便加以扩充。 因此,在您的 lo首中,它没有被分配价值。

total += interval;

Is wrong when total has no value assigned at all... What are you going to add interval too?

您应在使用之前首先确定总价值。

 TimeSpan total = new TimeSpan();,

然后,守则应当发挥作用。

没有任何初步价值被分配给总额。 你们在使用之前必须分配价值。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签