它显示语法错误“yield未声明。由于其保护等级,它可能无法进入 [英] Its showing a syntax error "yield is not declared. it may be inaccessible due to its protection level"
问题描述
这是我的代码,我将把它转换为vb.net。请帮帮我
this is my code which I am going to convert it to vb.net. Please help me out
public IEnumerable<DateTime> GetAllQuarters(DateTime current, DateTime past)
{
var curQ = (int)Math.Ceiling(current.Month / 3.0M);
var lastQEndDate = new DateTime(current.Year, curQ * 3, 1).AddMonths(-2).AddDays(-1);
do
{
yield return lastQEndDate;
lastQEndDate = lastQEndDate.AddMonths(-3);
lastQEndDate = new DateTime(lastQEndDate.Year, lastQEndDate.Month, DateTime.DaysInMonth(lastQEndDate.Year, lastQEndDate.Month));
} while (lastQEndDate >= past);
}
我的尝试:
公共函数GetAllQuarters(当前为DateTime,过去为DateTime)为IEnumerable(Of DateTime)
Dim curQ = CInt(Math.Ceiling(current.Month / 3D))
Dim lastQEndDate = New DateTime(current.Year,curQ * 3,1).AddMonths(-2).AddDays(-1)
确保
收益率返回lastQEndDate
lastQEndDate = lastQEndDate.AddMonths(-3)
lastQEndDate =新DateTime(lastQEndDate.Year,lastQEndDate.Month, DateTime.DaysInMonth(lastQEndDate.Year,lastQEndDate.Month))
循环当lastQEndDate> =过去
结束函数
What I have tried:
Public Function GetAllQuarters(current As DateTime, past As DateTime) As IEnumerable(Of DateTime)
Dim curQ = CInt(Math.Ceiling(current.Month / 3D))
Dim lastQEndDate = New DateTime(current.Year, curQ * 3, 1).AddMonths(-2).AddDays(-1)
Do
yield Return lastQEndDate
lastQEndDate = lastQEndDate.AddMonths(-3)
lastQEndDate = New DateTime(lastQEndDate.Year, lastQEndDate.Month, DateTime.DaysInMonth(lastQEndDate.Year, lastQEndDate.Month))
Loop While lastQEndDate >= past
End Function
推荐答案
检查VB.NET的Yield语法: Yield语句(Visual Basic) [ ^ ]
收益率应写成大写Y且不需要退货...同时检查报表的顺序(可能收益率应该是最后一个)...
Check Yield syntax for VB.NET: Yield Statement (Visual Basic)[^]
Yield should be written with capital Y and no return needed...Also check the order of statements (probably Yield should be the last)...
它只是收益率,而不是收益率收益率。
并且必须声明函数
it is just Yield, not Yield Return.
And the Function must be declared
Public Iterator Function GetAllQuarters
这篇关于它显示语法错误“yield未声明。由于其保护等级,它可能无法进入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!