Solved

abbreviate class and method in C #

Posted on 2014-11-10
3
120 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

763 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

9 Experts available now in Live!

Get 1:1 Help Now