本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

C# ドキュメント
C#
Getting Started with CSyntax BasicsTypes and DataProjects and PackagesErrors and TestingKey Concepts: LINQ, Delegates, and Async
ディスカッション

C# ガイド · 3/6

Types and Data

この章は現在、英語でのみ提供しています。

Every C# type is either a value type or a reference type, and that decides what happens when you assign, pass, or compare values. This chapter covers that split, classes, structs, records, properties, common collections, and null safety.

Value Types vs Reference Types

Built-in types such as int, double, bool, decimal, and DateTime, along with any struct or enum, are value types: the variable holds the data itself, so assignment copies it. Classes, string, arrays, and record classes are reference types: the variable holds a reference to an object, so assignment makes two variables point at the same object.

var p1 = new PointStruct { X = 1 };
var p2 = p1;             // copies the value
p2.X = 99;
Console.WriteLine(p1.X); // 1

var c1 = new PointClass { X = 1 };
var c2 = c1;             // copies the reference
c2.X = 99;
Console.WriteLine(c1.X); // 99

struct PointStruct { public int X; }
class PointClass { public int X; }

string is a reference type, but it is immutable and == compares contents, so it behaves like a value. Use structs for small, immutable data such as coordinates; classes are the default otherwise.

Classes and Properties

A class bundles data (fields and properties) with behavior (methods). Public data is exposed through properties rather than raw fields. A property has get and set accessors, so you can add validation later without breaking any calling code.

var account = new Account("Dana") { Number = "110-123-456" };
account.Deposit(500m);
Console.WriteLine($"{account.Owner}: {account.Balance:F2}");

public class Account
{
    private decimal _balance;

    public Account(string owner) => Owner = owner;

    public string Owner { get; }                 // read-only property
    public string? Memo { get; set; }            // auto-implemented property
    public required string Number { get; init; } // must be set at creation, then frozen

    public decimal Balance => _balance;          // computed property

    public void Deposit(decimal amount)
    {
        if (amount <= 0)
            throw new ArgumentOutOfRangeException(nameof(amount), "Deposit must be positive.");
        _balance += amount;
    }
}

An init accessor allows assignment only during object initialization (the { Number = ... } part), and required turns a forgotten assignment into a compile error. Notice that the statements come first and the class declaration follows: in a file with top-level statements, type declarations must come after the statements.

Records

Records are a concise way to declare types whose main job is carrying data. A positional record gets a constructor, read-only properties, value-based equality, and a readable for free.

この章について質問がありますか?
前の章Syntax Basics次の章Projects and Packages
ToString
var a = new Product("Mouse", 25.00m);
var b = new Product("Mouse", 25.00m);

Console.WriteLine(a == b);  // True: same contents means equal
Console.WriteLine(a);       // Product { Name = Mouse, Price = 25.00 }

var onSale = a with { Price = 19.99m }; // copy with one property changed

public record Product(string Name, decimal Price);

A with expression leaves the original untouched and returns a new record with the listed properties replaced. Plain record declares a reference type; write record struct when you want a value type instead.

Collections

The workhorses live in System.Collections.Generic: List<T> and Dictionary<TKey, TValue>. The type parameters in angle brackets let the compiler check what goes in and what comes out.

List<string> langs = ["C#", "F#", "Rust"];   // collection expression
langs.Add("Go");
langs.Remove("F#");
Console.WriteLine($"{langs.Count} items, first: {langs[0]}");

var stock = new Dictionary<string, int>
{
    ["apple"] = 10,
    ["pear"] = 4,
};
stock["plum"] = 7;                  // adds or overwrites

if (stock.TryGetValue("pear", out var pears))
    Console.WriteLine($"Pears in stock: {pears}");

foreach (var (fruit, qty) in stock)
    Console.WriteLine($"{fruit} = {qty}");

Reading a missing key with the indexer throws KeyNotFoundException, so use TryGetValue when a key may be absent. Other handy collections include HashSet<T> for unique items, Queue<T> for first-in-first-out, and Stack<T> for last-in-first-out. Fixed-size data fits naturally in an array such as int[].

Nullable Reference Types

With <Nullable>enable</Nullable> in the project file, the compiler tracks whether reference-type variables might be null. Plain string means "never null", while string? explicitly allows null. Using a maybe-null value without checking it produces a warning.

string? FindNickname(int userId) => userId == 1 ? "Sky" : null;

string? nick = FindNickname(2);

Console.WriteLine(nick?.Length);          // null if nick is null, no exception
Console.WriteLine(nick ?? "(no nickname)"); // fallback value
nick ??= "Guest";                          // assign only when null

if (nick is not null)
    Console.WriteLine(nick.ToUpper());     // compiler knows nick is non-null here

int? age = null;                           // nullable value type
Console.WriteLine(age.HasValue ? age.Value : -1);

?. skips the member access when the target is null, ?? supplies a default, and ??= fills in a value only if one is missing. When you are certain a value isn't null, the null-forgiving operator ! silences the warning, but it performs no runtime check, so use it sparingly.

Summary

  • Assigning a value type copies the data; assigning a reference type copies the reference.
  • Classes combine properties and methods, and init and required express how objects must be created.
  • Records give you value-based equality and non-destructive updates with with.
  • List<T> and Dictionary<TKey, TValue> cover most needs; use TryGetValue for safe lookups.
  • Nullable reference types, together with string?, ?., and ??, catch many null bugs at compile time.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。