Solved

abbreviate class and method in C #

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

739 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