Dear Sir,
I'm trying convert C# to VB.NET But I have an error `Error BC30188 Declaration expected. & Error BC30209 Option Strict On requires all variable declarations to have an 'As' clause.` In VB.NET
Please Guide me.
Thanks
Code In c#
public class item
{
public item(string _dt,int _MM,int _FC,int _AMS,int _KS)
{
dt = _dt;
MM = _MM;
FC = _FC;
AMS = _AMS;
KS = _KS;
}
public string dt { get; set; }
public int MM { get; set; }
public int FC { get; set; }
public int AMS { get; set; }
public int KS { get; set; }
}
List<item> _list=new List<item>();
_list.Add(new item("2023-01-01", 12, 13, 24, 26));
_list.Add(new item("2023-01-01", 22, 23, 44, 46));
_list.Add(new item("2022-12-01", 32, 13, 24, 26));
_list.Add(new item("2022-12-01", 42, 13, 64, 26));
_list.Add(new item("2023-11-10", 62, 13, 94, 36));
_list.Add(new item("2023-11-23", 02, 13, 34, 46));
var result = _list
.GroupBy(g =>
g.dt.Substring(0,7)
)
.Select(group => new
{
dateOfMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(int.Parse(group.Key.Split('-')[1]))
+ "-" + group.Key.Split('-')[0].Substring(2,2),
MM = group.Sum(s => s.MM),
FC = group.Sum(s => s.FC),
AMS = group.Sum(a => a.AMS),
KS = group.Sum(c => c.KS)
}).ToList();
Code in VB.NET
Public Class item
Public Sub New(ByVal _dt As String, ByVal _MM As Integer, ByVal _FC As Integer, ByVal _AMS As Integer, ByVal _KS As Integer)
dt = _dt
MM = _MM
FC = _FC
AMS = _AMS
KS = _KS
End Sub
Public Property dt As String
Public Property MM As Integer
Public Property FC As Integer
Public Property AMS As Integer
Public Property KS As Integer
End Class
Private _list As New List(Of item)()
`Error BC30188 Declaration expected. Below line code :
_list.Add(New item("2023-01-01", 12, 13, 24, 26))
_list.Add(New item("2023-01-01", 22, 23, 44, 46))
_list.Add(New item("2022-12-01", 32, 13, 24, 26))
_list.Add(New item("2022-12-01", 42, 13, 64, 26))
_list.Add(New item("2023-11-10", 62, 13, 94, 36))
_list.Add(New item("2023-11-23", 02, 13, 34, 46))
`Error BC30209 Option Strict On requires all variable declarations to have an 'As' clause.
Dim result = _list.GroupBy(Function(g) g.dt.Substring(0,7)).Select(Function(group) New With {
Key .dateOfMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Integer.Parse(group.Key.Split("-"c)(1))) & "-" & group.Key.Split("-"c)(0).Substring(2,2),
Key .MM = group.Sum(Function(s) s.MM),
Key .FC = group.Sum(Function(s) s.FC),
Key .AMS = group.Sum(Function(a) a.AMS),
Key .KS = group.Sum(Function(c) c.KS)
}).ToList()