Question Array Class and Output in Excel

Cauchy

Member
Joined
May 4, 2021
Messages
9
Programming Experience
Beginner
Hello Everyone,

i'm a newbie in this Community. I have some Problems in C#. First of all what i want to do ist the Following.

I want to make calculation in C# and the Output should be written in an Excel-Sheet. The First Colume should have Main-Values of a Contract and the Second Colume should have the additional Values. I have defined every cell in Excel, for example A1 has the name ZB and B1 ZB_add. Overall i have 40 Values, so 50 Values for the Main Part and 50 for the additional part. The only differ in the name, as you can see the additional one have at the end "_add".

What i have do in c#
1. write an Constructor where i declare only the Main Values. It looks likes this

public class Output
{
//declare Parameters
public double ZB;
public double HV;
....
}
public Output(double? ZB,double HV,...)
{
this.ZB=ZB;
this.HV=HV;
...
}
2. I write an Array class with:
Output out= new Output[2];
out[0]= new Output(value1,value2,...); //this are the main-values
out[1]= new Output(value1_add,value2_add,...); // this are the additional values


So far so good. How can i make the output in Excel as efficienc as possible. As you can see the cells only differ in the präfix "_add".

Thanks for helping :)
 
When i have
double [] jb = New double [2];
double [] xy = New double [2];
double [] zw = New double [2];
....

Can i declare many Array variables in an compact way?
Variables are variables. Why should array variables be any different to any other variables?

Also, you're not just declaring variables there. You are declaring variables, creating objects and assigning those objects to those variables.
 
The number of parameters are correct. If you have an contract like an insurance contract it is normaly that you have many parameters.
Yes. But at some point you have to decide you are not going to explicitly declare and name 50+ parameters, and use a dictionary or some other data structure instead to keep track of all those parameters.

Also consider calling a constructor or method with 50+ parameters. The potential for accidentally swapping the order of two parameters feels to be astronomically high, specially if all the parameters are the same type and the compiler won't warn you that you accidentally swapped two parameters around. Yes, C# 4.0 (?) started support for named parameters to help alleviate this problem, but now you go from just typing in:
C#:
var output = new Output(1.0, 2.5, ...);
to typing in:
C#:
var output = new Output(ZB: 1.0, HV: 2.5, ...);
(The same problem applies even if magic numbers are not used, and variables are passed into the constructor instead.)

Or are you not concerned about typing all those values in because you are the "software architect" and you have a bunch of "code monkeys" to actually do all real work and long term maintenance after you've created your proof of concept?
 
Back
Top Bottom