Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7044731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:26:40+00:00 2026-05-28T02:26:40+00:00

I have this on a button: private void Button_Click(object sender, RoutedEventArgs e) { string

  • 0

I have this on a button:

private void Button_Click(object sender, RoutedEventArgs e)
{
    string s = "x12y04";

    //make new instance for MyMath class
    MyMath dRet01 = new MyMath();

    //use the doubleArrayXY (in MyMath class) to get doubble array back
    double[] retD = dRet01.doubleArrayXY(s);

    //use the calcResultFromDoubleArray (in MyMath class) to get result
    MyMath dRet02 = new MyMath();
    double result = dRet02.calcResultFromDoubleArray(retD[0], retD[1]);

    //DEBUG!
    /*
    string TEST1 = Convert.ToString(returnedDouble[0]);
    MessageBox.Show(TEST1);
    string TEST2 = Convert.ToString(returnedDouble[1]);
    MessageBox.Show(TEST2);
    string TEST3 = Convert.ToString(result);
    MessageBox.Show(TEST3);
   */


}

where the class “MyMath” is:

public double[] doubleArrayXY(string inputValue)
{
    //in case there are upper case letters, set all to lower
    string inpLow = inputValue.ToLower();

    //split the string on the Y (so this tech should also work for x89232y329)
    //so this will create res[0] that is x89232 and an res[1] that is 329
    string[] res = inpLow.Split(new string[] { "y" }, StringSplitOptions.None);

    //in the first string that looks like x89232, remove the x
    string resx = res[0].Replace("x", null);

    //now get the x value to a double
    double x = double.Parse(resx);
    //now get the y valye to a double
    double y = double.Parse(res[1]);

    //return in a double array the x and then the y (x=double[0] and y=double[1])
    return new double[] {x,y};
}

public double calcResultFromDoubleArray(double one, double two)
{
    return (one * two);
}

Now I know the part in the class that is “calcResultFromDoubleArray” is kind of useless at this point, but I want to make that do some extra stuff later on.

what I wonder about the most is in the main code where I make this new dRet10, and later on make dRet02.

I was thinking at first I could do something like this:

double result = dRet01.calcResultFromDoubleArray(retD[0], retD[1]);

So in that case I would not need to create a new instance of MyMath, but this does not work.

So I need to call a new instance for the class (like I did), or can I do this in a more elegant way?
I’m still kind of new to C#, so I’m trying to learn how to program in a nice and elegant way, besides just making it work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:26:41+00:00Added an answer on May 28, 2026 at 2:26 am

    Since your methods don’t really use any other state information besides the parameters passed they probably should be static so you would not have to create any instances of your class at all:

    double[] retD = MyMath.DoubleArrayXY(s);
    double result = MyMath.CalcResultFromDoubleArray(retD[0], retD[1]);
    

    If all of your methods in MyMath are static, declare the class itself static – just like the System.Math class, so you cannot create instances at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: private void ModifyButton_Click(object sender, RoutedEventArgs e) { ModifyButton.Content = Another
im learning wpf for the first time, i have made this far private void
I have this button on the leftside of my UISplitViewController (RootViewController) that has a
I have this solution for a single button: myButton.Attributes.Add(onclick, this.disabled=true; + GetPostBackEventReference(myButton).ToString()); Which works
I have this code in the end of link button click: Response.ContentType = application/zip;
I have this code that has one button that let's me choose an entry
I have this little script to toggle a contact form when a button is
I have a button inside the content of a UIPopoverController. This button runs a
I have an asp.net page with a button. This button generates and inserts a
I have a GUI program with one Exit button. When clicking this button, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.