FAQ: Method Calls and Input - Named Arguments

This community-built FAQ covers the “Named Arguments” exercise from the lesson “Method Calls and Input”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C#

FAQs on the exercise Named Arguments

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I did call the name first (as I learned that parameters should be called within the right order), but Codecademy said, this was not right.

2 Likes

In regards to the orders, positional arguments are meant to be called prior named ones.

Positional ones are the arguments that don’t need to be specified within the parameters of your method (inside the Main method). The exercise expected you to use a named one to call your name.

1 Like

see this for better understanding of positional arguments friends

//+ named args

using System;

namespace NamedArguments

{

class Program

{

static void Main(string[] args)

{

func();               /// ans 01 02 03 04



//!func('1','2');

///: Argument 1: cannot convert from 'char' to 'string'

func("1");            /// ans 1 02 03 04

func("1","2","3","4");/// ans 1 2 3 4

func(th:"3");         /// ans 01 02 3 04

//!func(th:"3","1","11","111");

///: Named argument 'th' is used out-of-position 

/// but is followed by an unnamed argument



func("1","2",th:"3"); /// ans 1 2 3 04

func("1","2","3",fr:"4"); /// ans 1 2 3 4

func("1","2",fr:"4"); /// ans 1 2 03 4



//!func("1","11","111",tw:"2");

/// : Named argument 'tw' specifies a parameter 

/// for which a positional argument has already been given

}



static void func( string on = "01", string tw = "02",

  string th = "03" , string fr="04")

{

  Console.WriteLine($"ans {on} {tw} {th} {fr}");

}

}

}

put like , if you understand it well

The solution to this problem is not what it asks to do in the directions. It specifically says to use this formatting

VisitPlanets(a: “foo”, d: 4);

But the “actual answer” it wants you to do it this way

VisitPlanets();

  VisitPlanets(numberOfPlanets: 2);

  VisitPlanets(numberOfPlanets: 2, name: "Farfel");

These lessons are getting worse and worse the further along you go. They don’t make any sense half the time, the answers are broken, and the code will fail to work but it will progress the lesson. Losing faith in codecademy.