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 8166301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:48:58+00:00 2026-06-06T19:48:58+00:00

I have been trying to pass a string value from one method into another.

  • 0

I have been trying to pass a string value from one method into another. Here are my two methods.

Method 1-

public void listBox1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
    if (e.AddedItems.Count > 0)
    {
        var c_id = (e.AddedItems[0] as Foodlist).C_ID;
        string listboxid = c_id.ToString();
    }
}

I want the string listboxid value in my second method so that I can use it for comparison.
Method 2-

public void deletemyfood()
{
    using (FoodDataContext context = new FoodDataContext(Con_String))
    {
        string listboxindex = listboxid;
        IQueryable<FoodViewModel> foodQuery = from c in context.FoodTable where c.C_ID.ToString() == listboxindex select c;
        ....
    }
}

any ideas or suggestions?

  • 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-06-06T19:48:59+00:00Added an answer on June 6, 2026 at 7:48 pm

    Here’s a Simple example on how you can use return values and parameters:

    class Program
    {
        static void Main(string[] args)
        {
            var result = Method1("Test");
        }
    
       static string Method1(string input)
       {
           return string.Format("I got this input: {0}", input);
       }
    }
    

    In this example, the method Method1 takes a string parameter and then returns a string.

    In your case you might want to change the method signature of DeleteMyFood to this:

    public void DeleteMyFood(string foodId)

    If you want some sort of result though, too know when the method succeeded or not, you might want to have a value returned from the method as well. This can be done by modifying the method signature once again:

    public bool DeleteMyFood(string foodId)

    If I understand correctly based on your comments, you want to change the event handler to this:

    public void listBox1_SelectionChanged(object sender,
                                        System.Windows.Controls.SelectionChangedEventArgs e)
    {
        if (e.AddedItems.Count > 0)
        {
            var c_id = (e.AddedItems[0] as Foodlist).C_ID;
            string listboxid = c_id.ToString();
            DeleteMyFood(listboxid);
        }
    }
    

    This requires that the method DeleteMyFood accepts a parameter of type string, so we need to change that as well:

    public void deletemyfood(string foodId)
    {
        using (FoodDataContext context = new FoodDataContext(Con_String))
        {
            string listboxindex = listboxid;
            IQueryable<FoodViewModel> foodQuery = from c in context.FoodTable where c.C_ID.ToString() == foodId select c;
            // .. rest of code here ..
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass a String array from one activity to another but when
I've been having problems passing parameters from one .jsp to another. I have two
i have been using an actionListener to pass text from numerous TextFields into a
I have been trying to pass an int with the value of 1 to
i have been trying to pass some variables to model through the controller function
Have been trying to encrypt an xml file to a string so that I
I am trying to pass an array of Student into the function processStudent(string myFilename,
Have have been trying to make a validator for my xml files. I have
I have been trying to setup git for our web development team unsuccessfully. Some
I have been trying for almost a week now to create an SQLite database

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.