Helper.Perfornance.GenericBoxing 1.0.0

dotnet tool install --global Helper.Perfornance.GenericBoxing --version 1.0.0
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local Helper.Perfornance.GenericBoxing --version 1.0.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Helper.Perfornance.GenericBoxing&version=1.0.0
nuke :add-package Helper.Perfornance.GenericBoxing --version 1.0.0

Boxing & Unboxing in C# - EN

Boxing and unboxing are common terms used in programming languages like C#, and they refer to the conversion between value types and reference types.

Boxing

Boxing is the process of converting a value type (such as an int or double) to an object type (such as object). A value type variable is "boxed" into an object, and thus the value type variable can be used as an object type. However, this conversion process can cause performance loss because value types contain values directly, while objects contain references, which increases memory usage.

Unboxing

Unboxing is the process of converting the value inside a boxed object to its original value type. In other words, it is the conversion from an object type (such as object) to a value type (such as int or double).




Boxing & UnBoxing - TR

Boxing ve unboxing, genellikle C# gibi dillerde kullanılan terimlerdir ve genellikle değer tipleri ile referans tipleri arasında dönüşüm yapmayı ifade eder.

Boxing

Boxing, bir değer tipini (örneğin, bir int veya double gibi) bir nesne tipine (object gibi) dönüştürme işlemidir. Değer tipi olan bir değişken, bir nesne içine "kutulanır" ve böylece değer tipi olan değişken nesne tipi olarak kullanılabilir. Ancak, bu dönüşüm işlemi performans kaybına neden olabilir çünkü değer tipleri değerleri doğrudan içerirken, nesneler referansları içerir ve bu da bellek kullanımını artırır.

  • Örneğin, bir int'i bir nesne içine kutulamak için:
int num = 10;
object obj = num; // Boxing işlemi

Unboxing

Unboxing, kutulanmış bir nesnenin içindeki değeri orijinal değer tipine dönüştürme işlemidir. Yani, bir nesne tipinden (object gibi) değer tipine (int veya double gibi) dönüştürme işlemidir.

  • Örneğin, bir nesne içindeki değeri çıkarmak için:
object obj = 10; // Boxing yapılmış bir değer
int num = (int)obj; // Unboxing işlemi

Önemli Not

Boxing ve unboxing, bazı durumlarda ihtiyaç duyulan işlemlerdir, ancak performans açısından maliyetli olabilirler. Bu nedenle, gereksiz yere kullanılmamaları ve performans gereksinimleri göz önünde bulundurularak dikkatli bir şekilde kullanılmaları önemlidir.

Example

public class Example
{
    public static void Main()
    {
        string value = "Merhaba Dünya!";

        // Generic boxing with two type arguments
        var boxedValue = GenericBoxingUnboxing.Box<object, string>(value); // Specify both TBox and TValue

        // Generic unboxing
        string? unboxedValue = GenericBoxingUnboxing.Unbox<string>(boxedValue);

        Console.WriteLine(unboxedValue); // "Merhaba Dünya!" yazdırır
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
1.0.0 102 3/11/2024

Performance Helper