Click here to Skip to main content
16,020,701 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have create a method "ribsPoints()", its returning a list. I want to access to the specific list item at the list.

what is the best solution.

What I have tried:

static List ribsPoints()
{
List _rPoint = new List();
//first ribs
_rPoint.Add(new XYZ(firstRibSpacing, OuterStiffinerThick, 0));
_rPoint.Add(new XYZ(firstRibSpacing, PanelWidth - (2 * OuterStiffinerThick), 0));

return _rPoint;
}

C#


// call to the list item
void createSweep()
{
Sweep ribs = createRibs(fDoc, ribsPoints[i], ribsPoints().ElementAt(i));
}
Posted
Updated 2-Oct-20 20:11pm
Comments
BillWoodruff 3-Oct-20 0:33am    
You do not show the context (Classes) in which your code samples are defined and used. We can't read your mind.

Your usage of List is not generic (strongly typed), and the code will never compile.

1 solution

C# does not have a non-generic List class: the Generic version is List<T> and as such, your code will not compile without your writing your own List class - and if you wrote your own, then only you know how it works, what you can do with it, and so on.
The generic version would require different definitions:
C#
static List<Sweep> ribsPoints()
    {
    List<Sweep> _rPoint = new List<Sweep>();
    //first ribs
    _rPoint.Add(new XYZ(firstRibSpacing, OuterStiffinerThick, 0));
    _rPoint.Add(new XYZ(firstRibSpacing, PanelWidth - (2 * OuterStiffinerThick), 0));
    
    return _rPoint;
    }
And the XYZ class would have to be derived from the Sweep class.

If you have written your own List class which returns a holds a collection of Sweep objects, then it's at best poorly named from maintenance point of view!

So look at your code, and see what it is doing - we can't do that for you.
 
Share this answer
 
Comments
Member 12278335 3-Oct-20 10:56am    
Thank you very much for your replay.Form the method i wanted to do update list in different condition. After i tried like below. its works.
i create a list variable to get the list return from function and then the variable i used.
List<sweep> temp = new List<sweep>();
temp = ribsPoints();
// call to the list item
void createSweep()
{
Sweep ribs = createRibs(fDoc, temp[i], temp[i+1]);
}
OriginalGriff 3-Oct-20 11:21am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900