CKTIS / C#
new: praktická referencia
new: praktická referencia: new vytvorí objekt, pole či delegate alebo podľa kontextu skryje zdedený člen.
Verzia: C# language; verified against C# 14 reference
Syntax
new /* grammar-specific form */new vytvorí objekt, pole či delegate alebo podľa kontextu skryje zdedený člen.
Použite na explicitnú konštrukciu po overení povinných údajov.
Skrývanie pomocou new nie je polymorfizmus a závisí od statického typu referencie.
Konštruktor môže vyhodiť výnimku; target-typed new potrebuje jednoznačný typ z kontextu.
Úplný program skutočne používa new; presne očakávaný stdout je 2.
Príklady
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;
var value = new List<int> { 1, 2 }; Console.WriteLine(value.Count);
Výsledok
2
Úplný program skutočne používa `new`; presne očakávaný stdout je `2`.