# Keywords

## Access Keywords

### `base`

The `base` keyword is used to access members of the base class from within a derived class.

* Call a method on the base class that has been overridden by another method.

<pre class="language-csharp"><code class="lang-csharp">public class Person {
    protected string ssn = "444-55-6666";
    protected string name = "John L. Malgraine";
    public virtual void GetInfo() {
        Console.WriteLine("Name: {0}", name);
        Console.WriteLine("SSN: {0}", ssn);
    }
}

class Employee : Person {
    public string id = "ABC567EFG";
    public override void GetInfo() {
        // calling the base class GetInfo() method
<strong>        base.GetInfo();
</strong>        Console.WriteLine("Employee ID: {0}", id);
    }
}

class TestClass {
    static void Main() {
        Employee E = new Employee();
        E.GetInfo();
    }
}

/*
Output
Name: John L. Malgraine
SSN: 444-55-6666
Employee ID: ABC567EFG
*/
</code></pre>

* Specify which base-class constructor should be called when creating instances of the derived class.

<pre class="language-csharp"><code class="lang-csharp">public class BaseClass {
    int num;
    public BaseClass(){
        Console.WriteLine("in BaseClass()");
    }

    public BaseClass(int i) {
        num = i;
        Console.WriteLine("in BaseClass(int i)");
    }
}

public class DerivedClass : BaseClass {
    // This constructor will call BaseClass.BaseClass()
<strong>    public DerivedClass() : base() { }
</strong>
    // This constructor will call BaseClass.BaseClass(int i)
<strong>    public DerivedClass(int i) : base(i) { }
</strong>
    static void Main() {
        DerivedClass md = new DerivedClass();
        DerivedClass md1 = new DerivedClass(1);
    }
}
/*
Output:
in BaseClass()
in BaseClass(int i)
*/
</code></pre>

{% hint style="info" %}
It is an error to use the `base` keyword from within a static method.
{% endhint %}

## Contextual Keywords

### `partial`

Partial type definitions allow for the definition of a class, struct, interface, or record to be split into multiple files.

<pre class="language-csharp"><code class="lang-csharp">namespace PC
{
<strong>    partial class A
</strong>    {
        int num = 0;
        void MethodA() { }
        partial void MethodC();
    }
    
<strong>    partial class A
</strong>    {
        void MethodB() { }
        partial void MethodC() { }
    }
}
</code></pre>

All the parts must use the `partial` keyword, and must have the same accessibility, such as `public`, `private`, and so on. All the parts must be available at compile time to form the final type.

{% hint style="warning" %}
The `partial` keyword isn't allowed on constructors, finalizers, overloaded operators, property declarations, or event declarations.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dailyjournal.gitbook.io/notes/languages/c-sharp/keywords.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
