本文介绍了它显示语法错误“yield未声明。由于其保护等级,它可能无法进入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我将把它转换为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

推荐答案


Public Iterator Function GetAllQuarters


这篇关于它显示语法错误“yield未声明。由于其保护等级,它可能无法进入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 17:42