Visual Basic 2010问题 [英] Visual Basic 2010 Question

查看:59
本文介绍了Visual Basic 2010问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有人可以向我解释这个错误吗?我不知道该怎么做.

在此先感谢

未定义类型var

Hello All,

Please can someone explain this error to me? I don''t know what to make of it.

Thanks in Advance

Type var is not defined

Dim sb As New StringBuilder(50)
				Dim path As String = "..\debug\CarSalesFiles\Commissions" + DateTime.Today.Year + DateTime.Today.Month + DateTime.Today.Day + ".txt"
				If Not File.Exists(path) Then
					Using sw As StreamWriter = File.CreateText(path)
                        For Each item As var In result
                            sb.Append(item.SalesRepID + _seperator)
                            sb.Append(item.LastName + _seperator)
                            sb.Append(item.FirstName + _seperator)
                            sb.Append(item.PhotoFile + _seperator)
                            sb.Append(item.StartDate + _seperator)
                            sb.Append(item.Model + _seperator)
                            sb.Append(item.Manufacturer + _seperator)
                            sb.Append(item.Color + _seperator)
                            sb.Append(item.Year + _seperator)
                            sb.Append(item.OdometerReading + _seperator)
                            sb.Append(item.VehicleID + _seperator)
                            sb.Append(item.AcquisitionCost + _seperator)
                            sb.Append(item.AquiredDate + _seperator)
                            sb.Append(item.DateSold + _seperator)
                            sb.Append(item.MaintenanceCost + _seperator)
                            sb.Append(item.SellingPrice + _seperator)


		End Sub

推荐答案

在VB.NET中没有var这样的关键字,但是在C#中只有一个.这不是一种类型.并且您没有定义名为var的类型.代替var,显式使用适当的类型.

我不知道您的result类型,所以我也不知道item的类型,但是如果result的类型是集合或数组,请使用其元素类型.

背景:

支持for each的类型实现了通用接口System.Collections.IEnumerable<T>.方法System.Collections.IEnumerable.GetEnumerator返回实现接口System.Collections.IEnumerator<code><T>的类型的值.此类型与T类型的元素一起使用,这是for each循环的变量的类型.

所以:
There is not such keyword as var in VB.NET, but there is one in C#. And this is not a type. And you did not define type named var. Instead of var, use appropriate type explicitly.

I don''t know your result type, so I don''t know the type of item, but if the type of result is a collection or an array, use its element type.

Background:

The type supporting for each implements the generic interface System.Collections.IEnumerable<T>. The method System.Collections.IEnumerable.GetEnumerator returns a value of the type implementing the interface System.Collections.IEnumerator<code><T>. This type works with the elements of type T, and this is the type of the variable of for each loop.

So:
// Having

class SomeType { /* in fact, any type, not just class or structure */ }

class SomeEnumerableType : System.Collections.IEnumerable<SomeType> {
    System.Collections.IEnumerator<SomeType> System.Collections.IEnumerable<SomeType>.GetEnumerator() {
        //implementation of this interface
    }
    //...
}

// we can write:
SomeEnumerableType items = new SomeEnumerableType( /* ... */ ); 

For Each item As SomeType In items
    //...



请参阅:
http://msdn.microsoft.com/en-us/library/9eekhta0.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/78dfe2yb.aspx [ ^ ].

—SA



Please see:
http://msdn.microsoft.com/en-us/library/9eekhta0.aspx[^],
http://msdn.microsoft.com/en-us/library/78dfe2yb.aspx[^].

—SA


这篇关于Visual Basic 2010问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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