Click here to Skip to main content
15,918,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public Circle3D GetSphereCircle(BaseLibrary.VIEWCODE viewCode)
{
          
    List<vec3> VectorList = new List<vec3>();
    Vec3 vec = new Vec3(0, 0, 0);

     -----
   

    foreach (Vec3 vector in VectorList)
    {
        refPlane = new Plane3D(new Plane3(centPt, vector), false);
        circle = new Circle3D(new Circle3(centPt, _local_data._radius), refPlane, false);
    }
    return circle;
}

Above i am given short code snippet,i want to return each 'circle' generated in foreach loop,how i can do that?
Posted
Updated 17-May-15 21:18pm
v2
Comments
Anup6 18-May-15 3:02am    
I am tried using 'yield return' statement,but in my project above defined GetSphereCicle() is reffered by many other functions.so its complicated to change all these.so please suggest me any other way?
Tomas Takac 18-May-15 3:24am    
But the method returns only one circle. How do you want to return multiple circles without changing the return type? There is no other way, if you change the method you need to change all callers as well.
Anup6 18-May-15 4:14am    
I want to return multiple circles.i want to place 'return circle'statement in foreach block
Er. Ajay Chauhan 18-May-15 4:44am    
you are right.... you can put 'return' in foreach statement... try it... there will be no error in this.... ;-) :-P
Anup6 18-May-15 5:25am    
@Ajay,i m trying but got error as "Error'GetSphereCircle(BaseLibrary.VIEWCODE)': not all code paths return a value

A reasonable way is returning a container (e.g. a List) of circles, of course this implies changing the callers code, but any other approach (as far as I can see) would be rather involved.
 
Share this answer
 
To add to what CPallini has said - and he's right - the only other way to do it would involve a yield return: https://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx[^] making it into an iterator method.
 
Share this answer
 

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