1.2.10 Writing

Writing C# Means Turning a Design into Precise Source Code

In this part of PC1, you are moving from reading supplied code to writing small class definitions yourself.

The goal is not to write a complete application from memory.

The goal is to translate a clear design into readable, valid C#.

Start from the Model

Suppose the class diagram says:

Plain text
Player
-------------------------
name : string
jerseyNumber : int

The source should preserve:

A basic implementation can begin:

C#
class Player
{
    public string name;
    public int jerseyNumber;
}

Write Small Pieces Deliberately

A useful sequence is:

Plain text
class name
   ↓
opening and closing braces
   ↓
one field declaration
   ↓
next field declaration
   ↓
save
   ↓
build

Small steps make compiler feedback easier to interpret.

Preserve Exact Names from the Design

If the model says:

Plain text
jerseyNumber

do not casually rename it to:

Plain text
number

or:

Plain text
jersey

Names create a connection between requirements, UML, and source.

Use Formatting That Makes Structure Visible

Readable source:

C#
class Player
{
    public string name;
    public int jerseyNumber;
}

Indentation shows that the fields belong to the class.

Style rules may enforce additional conventions, but the basic goal is clear structure.

Build After a Focused Change

Writing code is an iterative process:

Plain text
write
  ↓
save
  ↓
build
  ↓
read diagnostics
  ↓
revise

Compiler feedback is evidence about the source you actually wrote.

The next activities make field declarations, naming, and access choices more precise.