I have a method GetSelectedServices() which returns Selected Nodes from a Tree List,
Expecting to return with the same method selected nodes and all Nodes i tried to add an out parameter.
But when I call this method i’m supposed to give the out parameter and so the returned list with selectedNodes is masked, and i cannot have it.
My Method
internal List<__ServiceInfo> GetSelectedServices(out List<__ServiceInfo> lstAll)
{
List<__ServiceInfo> lstSelected = new List<__ServiceInfo>();
List<__ServiceInfo> lstA = new List<__ServiceInfo>();
foreach (TreeListNode node in this.tlServices.Nodes)
{
if (node.Checked)
{
var service = this.tlServices.GetDataRecordByNode(node) as __ServiceInfo;
lstA.Add(service);
if (service != null)
{
lstSelected.Add(service);
}
if (node.Nodes.Count > 0)
{
foreach (TreeListNode subNode in node.Nodes)
{
if (subNode.Checked)
{
service = this.tlServices.GetDataRecordByNode(subNode) as __ServiceInfo;
lstA.Add(service);
if (service != null)
{
lstSelected.Add(service);
}
}
}
}
}
}
lstAll = lstA;
return lstSelected;
}
The way I call the method
public bool HasValidModel()
{
List<__ServiceInfo> lstAll = new List<__ServiceInfo>();
//here I get all nodes
var allServices = this.GetAllServices(out lstAll);
List<__ServiceInfo> lstSelected = new List<__ServiceInfo>();
//but how to get the list from ""return lstSelected"";
}
thank you for any suggestions.
Just use two variables, like this:
The ‘return’ed object is now referenced by
lstSelected, while theouted object is referenced bylst.