none
How do I call a "List" from a different method in a different project in the same solution?

    Question

  • List<double> measurements = new List<double>();
    double minimumx;
    double maximumx;
    double delta;
    double actualValues;
    //.
    //.
    //.
    //.
    //.Functionality of the above variables all stored as double
    //.
    //.
    //.
    //.

    How do I store all the above double variables into the List "measurements"? Can I use List.AddRange(). Also eventually I am trying to call the measurements onto a different project in the same solution( basically create a viewmodel.cs file and call the "measurements" list there ) and plot the measurements using oxyplot. How do I do the calling part?

    C#, Oxyplot, VisualStudio 2012
    Sunday, April 06, 2014 6:49 PM

Answers

  • Hi,

    >>Also eventually I am trying to call the measurements onto a different project in the same solution

    You could create a ClassLibraray project first, in this project, create a class:

    namespace ClassLibrary1
    {
        public class Class1
        {
            public List<double> measurements = new List<double>();
        }
    }

    Then, in the same solution, just create a Console application or Winform application, right-click project -> Add -> Reference... -> Solution -> Select ClassLibrary -> OK.

    Now, you can use measurements list in the program:

    using ClassLibrary1;
    
    ......
    
    Class1 c1 = new Class1();
    c1.measurements.Add(1.0);

    See also: http://msdn.microsoft.com/en-us/library/0fyc0azh%28v=VS.100%29.aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 07, 2014 7:54 AM

All replies

  • First the use of List.AddRange would be the variable name measurements.AddRange( ... ).  Also if you want to use databinding it needs to be a property not a field.

    As for the "calling" part, I assume you mean reference so can you expand on what you mean?


    Lloyd Sheen

    Sunday, April 06, 2014 8:29 PM
  • {
        class Class1
        {
            List<double> measurements = new List<double>();

    .....

    //measurements.Add(minimumx); //measurements.Add(maximumx); //measurements.Add(delta); //measurements.Add(actualValues);

    The above is what I did wrt adding on to the list.

    My question was how I access the elements of this list in another method in a different project.


    Sunday, April 06, 2014 8:50 PM
  • When you say access the list from another project, do you mean that the code we see is part of a DLL that would be referenced by other project as in a data access layer?

    Sorry for all the questions but your questions could be answered in too many way to be useful without further details from you.


    Lloyd Sheen

    Sunday, April 06, 2014 10:08 PM
  • I am fairly new to coding in Visual Studio. 

    I do not understand the syntax of how to call or access the list "measurements" in another class called "summoning".

    Sunday, April 06, 2014 10:17 PM
  • Hi,

    >>Also eventually I am trying to call the measurements onto a different project in the same solution

    You could create a ClassLibraray project first, in this project, create a class:

    namespace ClassLibrary1
    {
        public class Class1
        {
            public List<double> measurements = new List<double>();
        }
    }

    Then, in the same solution, just create a Console application or Winform application, right-click project -> Add -> Reference... -> Solution -> Select ClassLibrary -> OK.

    Now, you can use measurements list in the program:

    using ClassLibrary1;
    
    ......
    
    Class1 c1 = new Class1();
    c1.measurements.Add(1.0);

    See also: http://msdn.microsoft.com/en-us/library/0fyc0azh%28v=VS.100%29.aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 07, 2014 7:54 AM