--- id: csharp-class-members title: "C# Class Members" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["fields and methods C#", "public vs static C#", "C# 클래스 멤버"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.84 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["csharp", "programming-language", "w3schools", "oop", "class-members"] raw_sources: ["https://www.w3schools.com/cs/cs_class_members.php"] applied_in: [] github_commit: "" --- # [[CSharp Class Members]] ## 🎯 한 줄 통찰 (One-line insight) This chapter directly answers a question it poses itself — "why public, not static, like in the Methods chapter?" — with a crisp rule: `static` methods belong to the CLASS and need no object, while `public` methods belong to OBJECTS and can only be called through an instance; this reframes everything the Methods section taught (`static void MyMethod()`) as having been INCOMPLETE for real OOP use, since every method there was callable without ever creating an object — a limitation this chapter's Car/fullThrottle() example exists specifically to break. [S1] ## 🧠 핵심 개념 (Core concepts) - **Class members** — fields and methods declared inside a class, collectively. [S1] - **Fields** — variables inside a class; accessed via an object using dot syntax (`myObj.color`), can be assigned a default value inline or left blank and set later via the object. [S1] - **`static` vs. `public` methods** — `static` methods are callable WITHOUT creating an object (belong to the class); `public` methods require an object instance to call (belong to objects) — this is why object methods use `public`, not `static`. [S1] - **Method access via dot syntax** — `myObj.fullThrottle();`, same pattern as field access. [S1] - **Multiple objects, independent field values** — creating several objects of the same class (`Car Ford`, `Car Opel`) gives each its own independent copy of the fields. [S1] - **Multiple classes for organization** — one class (e.g. `Car`) holds fields/methods, another (e.g. `Program`) holds `Main()` and does the work; recommended practice. [S1] - **`public` as access modifier** — when fields need to be accessible from ANOTHER class (like `Program` accessing `Car`'s fields), those fields must be marked `public`; deferred full coverage to a later Access Modifiers chapter. [S1] ## 📖 세부 내용 (Details) - Field-only access: `class Car { string color = "red"; int maxSpeed = 200; static void Main(string[] args) { Car myObj = new Car(); Console.WriteLine(myObj.color); Console.WriteLine(myObj.maxSpeed); } }`. [S1] - Blank fields set via object: `string color; int maxSpeed; ... myObj.color = "red"; myObj.maxSpeed = 200;`. [S1] - Multiple independent objects: `Car Ford = new Car(); Ford.model = "Mustang"; ... Car Opel = new Car(); Opel.model = "Astra"; ...` — each object's fields are independent. [S1] - Object method call requiring `public`: `public void fullThrottle() { Console.WriteLine("The car is going as fast as it can!"); } ... myObj.fullThrottle();`. [S1] - Cross-class access with `public` fields: a `Car` class in one file exposes `public string model;` etc., and a separate `Program` class's `Main()` creates/uses `Car` objects. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **Methods 챕터의 static이 실제로는 제약이었음이 드러남**: Methods 챕터에서 배운 `static void MyMethod()`는 객체 생성 없이 클래스명만으로 호출 가능한 방식이었는데, 이번 챕터는 이것이 진짜 OOP의 "객체 메서드"와는 다른 것이며, 객체를 통해 호출하는 메서드는 반드시 `public`(static이 아님)이어야 한다는 점을 명확히 함 — Methods 챕터의 모든 예제가 사실 객체 없이도 동작하는 방식이었다는 한계가 이번 챕터에서 드러남. [S1] ## 🛠️ 적용 사례 (Applied in summary) Ford와 Opel 두 Car 객체를 만들어 각각 다른 model/color/year 값을 독립적으로 저장하고, fullThrottle() 메서드를 public으로 선언해 객체를 통해 호출하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1] ## 💻 코드 패턴 (Code patterns) static (class-level, no object needed) vs. public (object-level, requires an instance) methods (C#): ```csharp class Car { public string model; public void fullThrottle() // public -- called through an object { Console.WriteLine("The car is going as fast as it can!"); } } class Program { static void Main(string[] args) // static -- belongs to the class itself { Car myObj = new Car(); myObj.fullThrottle(); // requires the object instance } } ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.84 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[C# Tutorial]] - **관련 개념:** [[CSharp Classes]], [[CSharp Classes Multi]], [[CSharp Methods]], [[CSharp Access Modifiers]] - **참조 맥락:** OOP Basics 섹션 — Multiple Classes and Objects 챕터로 이어짐. ## 📚 출처 (Sources) - [S1] W3Schools — C# Class Members — https://www.w3schools.com/cs/cs_class_members.php ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# Class Members" page (Astra wiki-curation, P-Reinforce v3.1 format).