Solved

abbreviate class and method in C #

Posted on 2014-11-10
3
127 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This is about my first experience with programming Arduino.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

776 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