Accessing sub list data in a C# struct

I am trying to access data that is a sub list within a  datalist structure. The structure is as follows:

Field1
Field2
Field3
Field4
rawDataList (data I need to grab)
   0
     SubField1
       0 - Value I need to get
       1 - Value I need to get
       2 - Value I need to get
     Subfield2
     Subfield3
       0 - Value I need to get
       1 - Value I need to get
   1
     SubField1
       0 - Value I need to get
       1 - Value I need to get
       2 - Value I need to get
     Subfield2
     Subfield3
       0 - Value I need to get
       1 - Value I need to get
Field5

The following is what I thought would work but I get an error:

DateTime rTime;
            float rAmbient;
            float rTemp;
            float rVolt;

            for (int i = 0; i <= count; i++)
            {
                

                unsafe
                {
                    for (int t = 0; t <= 31; t++)
                    {
                        rTemp = _dataBase.rawDataList[i].temp[t];
                        rAmbient = _dataBase.rawDataList[i].tempAmbient;
                        rTime = _dataBase.rawDataList[i].time;
                        rVolt = _dataBase.rawDataList[i].v[t];
                      
                        rTable.Rows.Add(rTemp, rAmbient, rTime, rVolt);
                    }
                }     
            }

Open in new window


This is the error I get: Fixed size buffers can only be accessed through locals or fields

VS2013 directs me to MSDN but I cannot figure out how to fix the error. The error is with the temp and v values. Any  help or direction would be greatly appreciated...
LVL 1
snievesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TommySzalapskiCommented:
Is it a requirement that they are fixed arrays in the first place?
Why not just make v and temp ArrayLists and set the size in the constructor to whatever you want it to be?
0
käµfm³d 👽Commented:
Why are you using the unsafe modifier?
0
TommySzalapskiCommented:
It looks like you are trying to use an array because you used them in C++ or C. I'm guessing you added 'unsafe' because it made you do that to use the fixed arrays. You could probably also just use dynamic arrays. Use something like this to declare it
int[] temperature;

Open in new window

and something like this in the constructor
temperature = new int[31];

Open in new window


If you need more help, post the definition of the class.

Also note that your inner for loop is going to run 32 times. Is this intentional? I'm guessing it's for days in a month and you want < 31, not <= 31?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

snievesAuthor Commented:
It doesn't have to be in an array. The MSDN article I referenced said to create a variable and assign the in-line array to the variable. I did that and that is when I got the fixed size buffer error. The program is testing 32 modules for temp and voltage every second for a variable amount of time. I need to grab the data, the in-line array dataset and push that to SQL. The only part I'm having an issue with is getting the in-line array data. I did not generate the dataset, a different programmer handled that. Here is my code so far.

private void dbThread()
        {
            int count = _dataBase.rawDataList.Count();

            var timeStamp = DateTime.Now;
            var tID = Guid.NewGuid().ToString("N");

            // Summary data table //
            DataTable table = new DataTable();
            table.Columns.Add("ahDch", typeof(float));
            table.Columns.Add("moduleSN1", typeof(string));
            table.Columns.Add("moduleSN2", typeof(string));
            table.Columns.Add("newPackSN", typeof(string));
            table.Columns.Add("testType", typeof(string));
            table.Columns.Add("timeStamp", typeof(DateTime));
            table.Columns.Add("tID", typeof(string));
            table.Columns.Add("tIndex", typeof(string));

            for (int i = 0; i <= 31; i++)
            {
                table.Rows.Add(_dataBase.ahDch[i], _dataBase.moduleSN1[i], _dataBase.moduleSN2[i], _dataBase.newPackSN.Substring(36), _dataBase.testType, timeStamp, tID, i);
            }

            // Detail data table //
            DataTable rTable = new DataTable();
            rTable.Columns.Add("temp", typeof(float));
            rTable.Columns.Add("tempAmbient", typeof(float));
            rTable.Columns.Add("time", typeof(DateTime));
            rTable.Columns.Add("v", typeof(float));
            rTable.Columns.Add("timeStamp", typeof(DateTime));
            rTable.Columns.Add("tiD", typeof(string));
            rTable.Columns.Add("tIndex", typeof(string));

            
            float rTemp = 0;
            float rAmbient;
            DateTime rTime;
            float rVolt = 0;

            try
            {
                for (int i = 0; i <= count; i++)
                {
                    rAmbient = _dataBase.rawDataList[i].tempAmbient;
                    rTime = _dataBase.rawDataList[i].time;
                    ArrayList myArr = new ArrayList {_dataBase.rawDataList[i]};

                    unsafe
                    {
                        for (int t = 0; t <= 31; t++)
                        {
                            rTemp = myArr.temp[t]; // Does not contain a definition for temp
                            rVolt = myArr.v[t]; // Does not contain a definition for v
                            
                            rTable.Rows.Add(rTemp, rAmbient, rTime, rVolt, timeStamp, tID, i);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            
            string connectionString = "connection string";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
                {
                    bulkCopy.DestinationTableName = "dbo.Table1";

                    try
                    {
                         bulkCopy.WriteToServer(table);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                }

                using (SqlBulkCopy bulkCopy2 = new SqlBulkCopy(connection))
                {
                    bulkCopy2.DestinationTableName = "dbo.Table2_Items";

                    try
                    {
                        bulkCopy2.WriteToServer(rTable);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                }
            }

Open in new window


Thank you so much for your help!!!
0
TommySzalapskiCommented:
I was suggesting changing the actual temp array in the rawDataList to an ArrayList. But you say you can't change the definition of whatever type the rawDataList is? If you can't, then you'll have to work with it.

You didn't quite implement what the MSDN article suggested. You need something like this:

for (int t = 0; t <= 31; t++)
{
    WhateverTypeItIs temporaryVar =  _dataBase.rawDataList[i];
    rTemp = temporaryVar.temp[t];
}

Open in new window


At least, I think that's what you want. Without seeing the class that contains the fixed arrays, it's hard to be sure.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
snievesAuthor Commented:
Sorry for the delay. Worked like a charm. Thank you so much!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.