string[]

I have the following code:

 string[] parameters;
 string[] Allparameters;
foreach (var row in DealData)
                {
parameters = BuildParameters.AppendParameters(sNewNOIVector, sNewCapRateVector, sCMFDSCRCutoff1, sCMFValueAtLIQHaircutPCT1,sCMFBalloonREFILTVCutoff1,sCMFBALLOONNEXTLTVCutoff1, sCMFBalloonextAttemptNMOS1,row);
                }

Open in new window


I want to do enhance this code so that I can append the parameters for all rows in DealData in Allparameters. So, at the end of each for loop iteration, I want to move the contents of parameters element wise into AllParameters. AllParameters will finally have all the results from the iterations on DealData.

How can I code for this?

Thanks
camper12Asked:
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.

chaauCommented:
Use the temporary List<string> object that you can fill dynamically using the AddRange() method. Then convert it to Array using the ToArray(), like this:
string[] parameters;
string[] Allparameters;
List<string> allStrings = new List<string>();
foreach (var row in DealData)
{
  parameters = BuildParameters.AppendParameters(sNewNOIVector, sNewCapRateVector, sCMFDSCRCutoff1, sCMFValueAtLIQHaircutPCT1,sCMFBalloonREFILTVCutoff1,sCMFBALLOONNEXTLTVCutoff1, sCMFBalloonextAttemptNMOS1,row);
  allStrings.AddRange(parameters);
}
Allparameters = allStrings.ToArray();

Open in new window

0
senthil kumarCommented:
Hi, Here is what you expect.  Please mark resolve, if you accepted this.

string[] parameters;
 string[] Allparameters;
foreach (var row in DealData)
                {
parameters = BuildParameters.AppendParameters(sNewNOIVector, sNewCapRateVector, sCMFDSCRCutoff1, sCMFValueAtLIQHaircutPCT1,sCMFBalloonREFILTVCutoff1,sCMFBALLOONNEXTLTVCutoff1, sCMFBalloonextAttemptNMOS1,row);

Allparameters = Allparameters.Union(parameters).ToArray();

                }

Open in new window

0
senthil kumarCommented:
The above code of mine will have unique string in the destination string. suppose you may also want the duplicate strings, so the code will be,

string[] parameters;
 string[] Allparameters;
foreach (var row in DealData)
                {
parameters = BuildParameters.AppendParameters(sNewNOIVector, sNewCapRateVector, sCMFDSCRCutoff1, sCMFValueAtLIQHaircutPCT1,sCMFBalloonREFILTVCutoff1,sCMFBALLOONNEXTLTVCutoff1, sCMFBalloonextAttemptNMOS1,row);

Allparameters = Allparameters.Union(parameters,new myComparer()).ToArray();
}

 public class myComparer : IEqualityComparer<string>
    {

        public bool Equals(string x, string y)
        {
            return false;
        }



        public int GetHashCode(string obj)
        {
            return this.GetHashCode();
        }
    }

Open in new window

0
sarabandeCommented:
or

string[] parameters;
string[] Allparameters;
int len;
foreach (var row in DealData)
{
  parameters = BuildParameters.AppendParameters(sNewNOIVector, sNewCapRateVector, sCMFDSCRCutoff1, sCMFValueAtLIQHaircutPCT1,sCMFBalloonREFILTVCutoff1,sCMFBALLOONNEXTLTVCutoff1, sCMFBalloonextAttemptNMOS1,row);
  len = Allparameters.Length();
  Allparameters.Resize(parameters.Length() + len);
  Array.Copy(Allparameters, len, parameters, 0, parameters.Length());
}

Open in new window


Sara
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
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.