C# - Output value doesn't show up

Hi,

I am trying to retrieve a segment of a shattered curve following a basic set of rules,
The code seams to work, and all the if statement do get triggered, but it only outputs the segment itself in one of the cases.

Is it something related to the curve being a reference type?
I wrote the same logic in python and it behaves the same way…

Maybe the mistake is so obvious, I’ll add it here, otherwise there is a gh file in annex,

Thanks in advance for helping,

private void RunScript(
	List<Curve> Crvs,
	List<object> t,
	ref object Crv,
	ref object i)
    {
        // Write your logic here
        Console.WriteLine(Crvs.Count());

        if (Crvs.Count() == 3)
        {
            Console.WriteLine("Case 3 triggered");
            Crv = Crvs[1];
            i = 1;
            Console.WriteLine(Crv.GetType());
            
        }
        if (Crvs.Count() == 2)
        {
            if (t[0] == null)
            {
                Crv = Crvs[0];
                i = 0;
            }
            else
            {
                Crv = Crvs[1];
                i = 1;
            }
        }
        else
        {
            Crv = null;
            i = null;
        }
    }

Output segment from Curve list.gh (29.7 KB)

private void RunScript(
	List<Curve> Crvs,
	List<object> t,
	ref object Crv,
	ref object i)
    {
        // Write your logic here
        Console.WriteLine(Crvs.Count());

        if (Crvs.Count() == 3)
        {
            Console.WriteLine("Case 3 triggered");
            Crv = Crvs[1];
            i = 1;
            Console.WriteLine(Crv.GetType());
            
        }
        else if (Crvs.Count() == 2)
        {
            if (t[0] == null)
            {
                Crv = Crvs[0];
                i = 0;
            }
            else
            {
                Crv = Crvs[1];
                i = 1;
            }
        }
        else
        {
            Crv = null;
            i = null;
        }
    }

in your code in case you have 3, it writes the correct output and as it’s not 2, the else case is triggered, which reassigns null values.

1 Like

Aauuu, an inattention mistake… Well thank you very very first for finding the reason why! It works nicely like that, thanks!

1 Like