Visual Basic 2010问题 [英] Visual Basic 2010 Question
本文介绍了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 asvar
in VB.NET, but there is one in C#. And this is not a type. And you did not define type namedvar
. Instead ofvar
, use appropriate type explicitly.
I don''t know yourresult
type, so I don''t know the type ofitem
, but if the type ofresult
is a collection or an array, use its element type.
Background:
The type supportingfor each
implements the generic interfaceSystem.Collections.IEnumerable<T>
. The methodSystem.Collections.IEnumerable.GetEnumerator
returns a value of the type implementing the interfaceSystem.Collections.IEnumerator<code><T>
. This type works with the elements of typeT
, and this is the type of the variable offor 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 [ ^ ].
Please see:
http://msdn.microsoft.com/en-us/library/9eekhta0.aspx[^],
http://msdn.microsoft.com/en-us/library/78dfe2yb.aspx[^].
这篇关于Visual Basic 2010问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文