Provide longer example of C# code to coding convention #101

Closed
opened 2026-04-01 13:41:09 +00:00 by a24vinla · 2 comments
Collaborator

When C# code that follows our code conventions exists, add to the wiki page

Parent Issues: #76 #82

When C# code that follows our code conventions exists, add to the wiki page Parent Issues: #76 #82
Collaborator
/// <summary>
/// This class shows the coding standard, and some examples of what not to do.
/// </summary>
class HelloWorldProgram
{
    /// <summary>
    /// The classes main function. 
    /// Declares constants and then calls upon CoolMath method.
    /// Outputs resulting value from the CoolMath method.
    /// </summary>
    /// <param name="args">A string array that can take diverse arguments.</param>
    static void Main(string[] args)
    {
        const int VarX = 5; const int VarY = 10; 
        // Bad way to declare two constants, should be two lines.
        string outPut = CoolMath(VarX, VarY);

        Console.WriteLine(outPut);
    }

    /// <summary>
    /// A method to show coding standards and print hello world.
    /// It compares varX with varY and 0, and if within limits it prints "Hello world!"
    /// Otherwise it prints "Nothing here."
    /// </summary>
    /// <param name="varX">An int that gets compared with 0 and varY.</param>
    /// <param name="varY">An int that gets compared with varX.</param>
    /// <returns>Returns a string with either "Hello world!" or "Nothing here."</returns>
    static string CoolMath(int varX, int varY)
    {
        string coolName = "Hello world!";

        if ((varX < varY) && (varX > 0))
        {
            return (coolName);
        }
        else 
        {
            return "Nothing here.";
        }
    }
}

Does this look okay? Should I change/add something?

``` /// <summary> /// This class shows the coding standard, and some examples of what not to do. /// </summary> class HelloWorldProgram { /// <summary> /// The classes main function. /// Declares constants and then calls upon CoolMath method. /// Outputs resulting value from the CoolMath method. /// </summary> /// <param name="args">A string array that can take diverse arguments.</param> static void Main(string[] args) { const int VarX = 5; const int VarY = 10; // Bad way to declare two constants, should be two lines. string outPut = CoolMath(VarX, VarY); Console.WriteLine(outPut); } /// <summary> /// A method to show coding standards and print hello world. /// It compares varX with varY and 0, and if within limits it prints "Hello world!" /// Otherwise it prints "Nothing here." /// </summary> /// <param name="varX">An int that gets compared with 0 and varY.</param> /// <param name="varY">An int that gets compared with varX.</param> /// <returns>Returns a string with either "Hello world!" or "Nothing here."</returns> static string CoolMath(int varX, int varY) { string coolName = "Hello world!"; if ((varX < varY) && (varX > 0)) { return (coolName); } else { return "Nothing here."; } } } ``` Does this look okay? Should I change/add something?
Author
Collaborator

I think it looks good! Clearly shows the structure that we want with good examples of XML-comments. Will add to the wiki!

I think it looks good! Clearly shows the structure that we want with good examples of XML-comments. Will add to the wiki!
a24vinla 2026-04-09 07:26:36 +00:00
Sign in to join this conversation.
No milestone
No project
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K#101
No description provided.