الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.
إكسير

إكسير مايكروسوفت دوت نت كود رقم 0001

بدأه Phoenix Programmer في 26 يونيو 2016 · 0 رد · 378 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1

What is the difference between using Empty String (“”) vs (string.Empty) in Microsoft Dot Net Programming Code?

Answer using C# Dot Net Programming Language:

Code 1: string textValue = “”;

Code 2: string textValue = string.Empty;

Code 1: each time empty string quotes are found, they are translated to a new empty string object. So, each “” is a new allocated useless object in memory especially for string since string object is an Immutable object (Any action with the object will lead to new allocated object and not modify the used object).

Code 2: each time string.Empty is used, all empty string variables are assigned to only one static string object which reduces memory used for empty strings by assigning all empty strings to only one global empty string object which has special MSIL code in Dot Net to handle all empty strings as only one global string object during Active Dot Net framework life time.

Note: there are tests on the internet shows a very small difference in speed (Milliseconds) which means nothing in most applications, but the main point here is reducing memory mainly and reducing number of useless objects the Garbage Collector need to release from memory.

Dot Net Code Elixir Number 0001:
https://goo.gl/9ZDBez

Draft 0001 Dot Net Code Elixir E-Book:
https://goo.gl/HrygWP

مواضيع مشابهة