Skip to content

msrudich/static-methods-compiler-errors

Repository files navigation

Static Methods - Compiler Errors

Beginner level task to practice fixing the most common compiler errors.

Estimated time to complete the task - 1h.

The task requires .NET 6 SDK installed.

Task Description

The task has five sub-tasks. Each sub-task is a small coding exercise.

CS0103

  1. Build the solution.
    • Click on the menu item - Build\Build Solution.
    • Or use the default keyboard shortcut - Ctrl+Shift+B (different versions of Visual Studio may have different keyboard shortcuts. See Keyboard shortcuts in Visual Studio article).

Build Solution

  1. Open the Error List view.
    • Click on the menu item - View\Error List.
    • Or use the default shortcut - Ctrl+\, E.

View Error List

  1. Find an error with CS0103 code and review the error in detail by clicking on the link in the "Code" column.

Open CS0103

You will get to the issue documentation page.

  1. Double-click on the CS0103 issue in the Error List window.

Navigate to CS0103

You will get to the CS0103/MyClass.cs file.

CS0103

  1. Read the documentation page and learn how to fix the error: "Check the spelling of the name and check your using directives and assembly references to make sure that the name that you are trying to use is available."

  2. Replace the name of the method called in the return statement with correct spelling - ReturnInt.

public static int MyMethod()
{
    return ReturnInt(intParameter: 534_947_886);
}
  1. Rebuild the solution.

Rebuild Solution

  1. Open the Error List window again and make sure there are no CS0103 issues.

CS0117

CS0117

  1. Open the Error List window, find the CS0117 issue.
  2. Open and read the issue documentation page.
  3. Navigate to the code by clicking on the issue line in Error List window.
  4. Replace the name of the method called in the return statement with correct spelling - ReturnLong.
public static long MyMethod()
{
    return AnotherClass.ReturnLong(longParameter: 49_023_471L);
}
  1. Rebuild the solution.
  2. Open the Error List window again and make sure there are no CS0117 issues anymore.

CS1501

CS1501

Fix the issue by removing the method argument from the method call.

public static int MyMethod()
{
    return ReturnInt();
}

CS1739

CS1739

Fix the issue by replacing the named parameter with correct argument name.

public static int MyMethod()
{
    return ReturnInt(intParameter: 9_389_572);
}

CS7036

CS7036

Fix the issue by adding the parameter to the ReturnInt method call.

public static int MyMethod()
{
    return ReturnInt(5_689_375);
}

Fix Compiler Issues

Additional style and code checks are enabled for the projects in this solution to help you maintaining consistency of the project source code and avoiding silly mistakes. Review the Error List in Visual Studio to see all compiler warnings and errors.

If a compiler error or warning message is not clear, review errors details or google the error or warning code to get more information about the issue.

Task Checklist

  1. Rebuild the solution.
  2. Fix all compiler warnings and errors. Make sure there are no warnings and errors in Error List.

Output and Error List

  1. Run all unit tests, make sure all unit tests completed successfully.

Test Explorer

  1. Review all changes, make sure that only the code files (.cs) in CompilerErrors project are changed.

Good Git Changes

Do not make any changes to project files (.csproj) or in code files in CompilerErrors.Tests project.

Bad Git Changes

  1. Stage your changes.

Stage Changes

All your changes are staged now.

Staged Changes

  1. Create a commit and push your changes to remote repository.

Commit and Push

See also

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages