Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

namespace: practical reference

namespace: practical reference: namespace groups names and prevents collisions without creating a runtime object.

Version: C# language; verified against C# 14 reference

Syntax

namespace /* grammar-specific form */

namespace groups names and prevents collisions without creating a runtime object.

Use it consistently with domain boundaries and the public API.

A namespace is neither an access boundary nor a deployment module.

File-scoped and block-scoped forms cannot be mixed arbitrarily in one file.

The complete program actually uses namespace; its exact expected stdout is 4.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

Console.WriteLine(new Demo.Value().Number);
namespace Demo { sealed class Value { public int Number => 4; } }

Result

4

The complete program actually uses `namespace`; its exact expected stdout is `4`.

Sources