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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:49:19+00:00 2026-05-26T10:49:19+00:00

This is a really simple question concerning a method. I’m pretty new to C#

  • 0

This is a really simple question concerning a method. I’m pretty new to C# and am testing lists. How do I call the method “addTwo” so that it updates every element in the “Marks” list by two? Please note that I’ve already created this method (scroll down further below the main method). I just want to know how to call it in the main method.

namespace ParallelLists
    {
        class Program
        {
            static void Main(string[] args)
            {
                //create an list of 4 student names
                List<string> names = new List<string>(4);
                names.Add("Matt");
                names.Add("Mark");
                names.Add("Luke");
                names.Add("John");

                //create a list of 4 integers representing marks
                List<decimal> marks = new List<decimal>(4);
                marks.Add(88m);
                marks.Add(90m);
                marks.Add(55m);
                marks.Add(75m);


                Console.WriteLine("the mark of " + names[0] + " is : " + marks[0]);
                Console.ReadLine();

                //Upgrade everyone by 2 marks
               ...   
            }

            public List<decimal> addTwo(List<decimal> mark)
            {
                List<decimal> temp = mark;
                for (int i = 0; i < temp.Count; i++)
                {
                    temp[i] += 2m;
                }
                return temp;
            }
        }
    }
  • 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-26T10:49:19+00:00Added an answer on May 26, 2026 at 10:49 am

    You need to make your method static, since you are accessing on a non object. also you need to update your marks collection with the returned value. You dont actually need to return the List because list is mutable.

    class Program
    {
        static void Main(string[] args)
        {
            //create an list of 4 student names
            List<string> names = new List<string>(4);
            names.Add("Matt");
            names.Add("Mark");
            names.Add("Luke");
            names.Add("John");
    
            //create a list of 4 integers representing marks
            List<decimal> marks = new List<decimal>(4);
            marks.Add(88m);
            marks.Add(90m);
            marks.Add(55m);
            marks.Add(75m);
    
    
            marks = addTwo(marks);
    
            Console.WriteLine("the mark of " + names[0] + " is : " + marks[0]);
            Console.ReadLine();
    
            Console.Read();
    
        } 
    
        public static List<decimal> addTwo(List<decimal> mark)
            {
                List<decimal> temp = mark;
                for (int i = 0; i < temp.Count; i++)
                {
                    temp[i] += 2m;
                }
                return temp;
            }
    }
    

    if you dont want to return the list, you can do the following:

    class Program
        {
            static void Main(string[] args)
            {
                //create an list of 4 student names
                List<string> names = new List<string>(4);
                names.Add("Matt");
                names.Add("Mark");
                names.Add("Luke");
                names.Add("John");
    
                //create a list of 4 integers representing marks
                List<decimal> marks = new List<decimal>(4);
                marks.Add(88m);
                marks.Add(90m);
                marks.Add(55m);
                marks.Add(75m);
    
    
                addTwo(marks);
    
                Console.WriteLine("the mark of " + names[0] + " is : " + marks[0]);
                Console.ReadLine();
    
                Console.Read();
    
            }
    
            public static void addTwo(List<decimal> mark)
            {
                List<decimal> temp = mark;
                for (int i = 0; i < temp.Count; i++)
                {
                    temp[i] += 2m;
                }
    
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a (hopefully) really simple question - I have been told recently that
This sounds like a really simple question, but I am new to PHP. If
This is a simple question really. I've been using the new type of constructors
I'm fairly new to Rspec so apologies if this is a really simple question:
I'm new to the entity framework so hopefully this is a really simple question...
I know that this is a really simple question, but where should I place
I guess this is a really simple question and, probably, one that has been
This is a really simple question, but I can't seem to find the answer.
I know this is a really simple question but my google-fu is failing me.
This is probably a really simple question but... I would like to do a

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.