Solved

abbreviate class and method in C #

Posted on 2014-11-10
3
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 63

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

717 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