Skip to content

Completed Example Guide

This guide explains how to use the completed C# implementation as a reference during the workshop.

📂 Location of Completed Example

The completed C# implementation is available in:

src/csharp-app-complete/

This directory contains a fully working C# implementation of the weather API that you can reference at any time during the workshop.

🎯 When to Use the Completed Example

Appropriate Times to Reference:

  1. When You're Stuck
  2. You've tried debugging for 10+ minutes
  3. Error messages aren't helping
  4. You want to compare your approach with a working solution

  5. To Understand Patterns

  6. How should JSON deserialization be structured?
  7. What's the correct way to organize endpoints?
  8. How are models typically defined in C#?

  9. For Code Comparison

  10. Your code works but you want to see alternatives
  11. Checking if your implementation follows best practices
  12. Understanding different approaches to the same problem

  13. When Time is Limited

  14. You're behind schedule and need to catch up
  15. You want to see the end result to understand the goal
  16. Workshop is ending and you want to see completion

⚠️ Times to Avoid:

  1. Before Attempting Yourself
  2. Don't copy-paste without understanding
  3. Try your own solution first
  4. Use GitHub Copilot before looking at the answer

  5. When You're Learning

  6. Struggling is part of learning
  7. Making mistakes helps you learn
  8. Problem-solving builds skills

🔍 How to Use the Completed Example Effectively

Step 1: Try It Yourself First

1. Attempt the task using GitHub Copilot
2. Debug if you encounter issues
3. Spend at least 5-10 minutes trying to solve it
4. THEN look at the completed example if still stuck

Step 2: Compare, Don't Copy

When referencing the completed example:

✅ DO: Read and understand the logic
✅ DO: Note the patterns and structure
✅ DO: Compare with your implementation
✅ DO: Close the file and try to apply what you learned

❌ DON'T: Copy-paste entire files
❌ DON'T: Use it without understanding
❌ DON'T: Skip trying your own solution first

Step 3: Ask Questions

If you don't understand something in the completed example:

  • Ask GitHub Copilot to explain specific code sections
  • Ask a proctor to walk you through the logic
  • Reference the inline comments (see below)

📖 Understanding the Completed Code

The completed example includes comments explaining key decisions. Here's what to look for:

Program.cs Structure

// 1. Builder configuration
//    - Adds services like Swagger
//    - Configures JSON serialization

// 2. App configuration
//    - Sets up middleware
//    - Enables Swagger in development

// 3. Endpoint definitions
//    - Each endpoint is clearly separated
//    - Comments explain the logic

// 4. Data loading
//    - JSON file is read once at startup
//    - Deserialized into strongly-typed models

Key Patterns to Note

1. JSON Deserialization:

// The weather data is loaded once and cached
// This is more efficient than reading the file on every request
var weatherData = JsonSerializer.Deserialize<WeatherData>(json);

2. Endpoint Structure:

// Endpoints follow a consistent pattern:
// 1. Define the route
// 2. Implement the logic
// 3. Return appropriate status codes
// 4. Add OpenAPI documentation

3. Error Handling:

// Always check for null/invalid data
// Return appropriate HTTP status codes (404, 400, 200)
// Provide meaningful error messages

🏃 Running the Completed Example

You can run the completed example to see how it should work:

# Navigate to completed example
cd src/csharp-app-complete

# Run the application
dotnet run --urls "http://localhost:8000"

# In another terminal, run tests
cd src/python-app/webapp
pytest test_main.py -v

Expected Result: All tests should pass ✅

🎓 Learning from the Completed Example

Exercise 1: Code Reading

  1. Open src/csharp-app-complete/Program.cs
  2. Read through the code from top to bottom
  3. For each endpoint, identify:
  4. What HTTP method is used (GET, POST, etc.)
  5. What parameters it accepts
  6. What it returns
  7. How errors are handled

Exercise 2: Pattern Recognition

Compare your code with the completed example:

Aspect Your Implementation Completed Example Notes
JSON Loading
Endpoint Structure
Error Handling
Data Models

Exercise 3: Improvement Ideas

After reviewing the completed example:

  1. What could you improve in your implementation?
  2. What patterns from the completed code would you adopt?
  3. Are there differences that are just stylistic vs. functional?

🔄 Comparing Approaches

It's valuable to see that there are multiple correct ways to solve problems:

Your Approach Might Differ In:

  • Variable naming - As long as it's clear, it's fine
  • Code organization - Different structures can both work
  • Error handling specifics - Various approaches are valid
  • Comment style - Your style may differ

Your Approach Should Match In:

  • Endpoint behavior - Must match Python API
  • Status codes - Should return correct HTTP status codes
  • JSON structure - Response format should match
  • Error responses - Should handle errors appropriately

📚 Additional Resources in Completed Example

Files to Review:

src/csharp-app-complete/
├── Program.cs           # Main application file
├── Models.cs           # Data models (if separated)
├── weather.json        # Same data file as Python version
└── *.csproj           # Project configuration

What Each File Teaches:

Program.cs: - How to structure a Minimal API - Service configuration - Endpoint implementation - Swagger setup

Models.cs (if present): - C# class structure - JSON property mapping - Data type choices

weather.json: - Data structure - How JSON maps to C# models

🎯 Best Practices Demonstrated

The completed example demonstrates several best practices:

  1. Single Responsibility - Each endpoint does one thing
  2. Error Handling - Appropriate status codes and messages
  3. Code Organization - Clear structure and flow
  4. Documentation - Swagger annotations for API docs
  5. Performance - Data loaded once, not per request
  6. Type Safety - Strongly typed models prevent errors

💡 Tips for Proctors

When guiding attendees to use the completed example:

Encourage Self-Discovery:

"Have you looked at the completed example in src/csharp-app-complete?
Let's look at how that endpoint is structured and see if it helps."

Guide Comparison:

"Open your Program.cs and the completed Program.cs side by side.
What differences do you notice? Which approach do you prefer and why?"

Promote Understanding:

"Don't just copy - try to understand why it's structured that way.
Can you explain what this section does?"

🚫 Academic Integrity Note

While this is a workshop and not graded:

  • Learning happens through struggle - Don't short-circuit your learning
  • Understanding is the goal - Not just getting it done
  • Ask for help - Proctors and Copilot are here to support you
  • Compare, don't copy - Use it as a reference, not a shortcut

Summary

The completed example is a learning tool, not a shortcut:

✅ Use it when stuck after genuine effort
✅ Use it to understand patterns and best practices
✅ Use it to compare approaches
✅ Use it to verify your understanding

❌ Don't use it to skip the learning process
❌ Don't copy without understanding
❌ Don't look before attempting yourself

Remember: The goal is to learn how to work with GitHub Copilot and migrate code between languages. The completed example supports that goal, but the real value is in the journey of solving problems with AI assistance.


Quick Reference

Location: src/csharp-app-complete/
When to use: After attempting yourself
How to use: Compare and understand, don't copy
Why it exists: To show a complete, working solution
Best approach: Try → Debug → Compare → Learn → Apply