Solved

abbreviate class and method in C #

Posted on 2014-11-10
3
125 Views
Last Modified: 2014-11-10
Hi,

I use this to reduce code.
var csx= string.Format("csv_{0:00}_{1:00}", m, h);
var ch2 = this.chart2_7.ChartAreas[0];
VarClas VC=new VarClas();

Open in new window


How to reduce code in this case?
My app have a class called VarClas.cs and inside have a method called
public class keisoku 
{
            public static double f2_nUD_D1;
            public static double f2_nUD_D2;
            public static double f2_nUD_D3;
            public static double f2_nUD_D4;
            public static double f2_nUD_D5;
            public static double f2_nUD_D6;
}

Open in new window


Thanks in advance,
ocaccy
0
Comment
Question by:ocaccy
3 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 250 total points
ID: 40432760
Do you mean like this:
public class keisoku
{
            public static double f2_nUD_D[6];
}

Note this uses an array instead of six variables - you would need to rewrite the code that calls this function
0
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 40432853
Hi ocaccy;

You can create a Dictionary object which uses a Key/Value pair. Using the key value as the Key in which to store a value and using the Value to store the value for the key as shown below.

// Create a Dictionary which will hold the value of f2_nUD_DX where X is the Key of the Dictionary
var f2_nUD_D = new Dictionary<int, double>() {{1, 0.0}, {2, 0.0}, {3, 0.0}, {4, 0.0}, {5, 0.0}, {6, 0.0}};

// Then to modify the values you can do the following, modify f2_nUD_D3 as follows
f2_nUD_D[3] = 12.76;

// To get the value in f2_nUD_D3 you can do the following
var d3 = f2_nUD_D[3];

Open in new window

0
 

Author Comment

by:ocaccy
ID: 40433993
Andy and Fernando, Great!

Now; how to call this VarClas.Keisoku.f2_nUD_D[x] in another class reducing VarClass.keisoku to VCK?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now