pttoy
asked on
C# syntax (class library returning a generic list)
This should be simple for C# developers. I am new to the language and syntax.
Here is some basic VB.net code which I use all the time to access a class library call which returns a list(of structure)
How would I write this code in C#.
Dim myEmp As New clsLibrary.Employees
Dim myList As New List(Of clsLibrary.Employees.Emplo
myList = myEmp.getStructEmployeeLis
Dim query = From emp In myList Order By emp.LastName, emp.FirstName
For Each item In query
Response.Write(item.LastNa
Next
Thanks!
ASKER
Close, but not quite there yet....
I am getting the following error message at the below line.
dynamic query = from emp in myListorderby emp.LastName, emp.FirstName
Error Message:
cannot implicitly convert type object to System.Collection.Generic. List<clsLi brary.Empl oyees.Empl oyees_Stru cture>
An explicit conversion exists (are you missing a cast?)
Thanks,
I am getting the following error message at the below line.
dynamic query = from emp in myListorderby emp.LastName, emp.FirstName
Error Message:
cannot implicitly convert type object to System.Collection.Generic.
An explicit conversion exists (are you missing a cast?)
Thanks,
Please try the following this version is closer to your VB.NET code:
// .NET Framework 3.0+
var myEmp = new clsLibrary.Employees();
var myList = new List<clsLibrary.Employees.Employees_Structure>();
myList = myEmp.getStructEmployeeList("SEN", "Active");
var query = from emp in myList orderby emp.LastName, emp.FirstName;
foreach (var item in query)
{
Response.Write(item.LastName + "<br/>");
}
Oops. I missed the select on the Linq query. There you go:
// .NET Framework 3.0+
var myEmp = new clsLibrary.Employees();
var myList = new List<clsLibrary.Employees.Employees_Structure>();
myList = myEmp.getStructEmployeeList("SEN", "Active");
var query = from emp in myList orderby emp.LastName, emp.FirstName select emp;
foreach (var item in query)
{
Response.Write(item.LastName + "<br/>");
}
ASKER
Thank You wdosanjos,
I'm still getting an error at the following line:
myList = myEmp.getStructEmployeeLis
Error Message:
cannot implicitly convert type object to System.Collection.Generic.
An explicit conversion exists (are you missing a cast?)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You
Open in new window