In this series I answer various .NET questions. Some of them are asked during interviews, some of them I see on the internet, some of them are completely made up. The goal is to provide short answer with links to references if needed. This is by no means a .NET tutorial or experts reference, this is just a bunch of useful answers to refresh your knowledge.
C# 8 و پس از آن
کدنویسی شهودی با ادیتور Algojammer
Algojammer is an experimental, proof-of-concept code editor for writing algorithms in Python. It was mainly written to assist with solving the kind of algorithm problems that feature in competitions like Google Code Jam, Topcoder and HackerRank
مقایسه عملکرد HTTP/3 با HTTP/2
Parallel.For & Parallel.ForEach
var nums = Enumerable.Range( 0, 1000000 ).ToArray(); long total = 0; // Use type parameter to make subtotal a long, not an int Parallel.For< long >( 0, nums.Length, () => 0, ( j, loop, subtotal ) => { subtotal += nums[j]; return subtotal; }, x => Interlocked.Add( ref total, x ) ); Console.WriteLine( "The total is {0:N0}", total );
var nums = Enumerable.Range( 0, 1000000 ).ToArray(); long total = 0; Parallel.ForEach< int, long >( nums, // source collection () => 0, // method to initialize the local variable ( j, loop, subtotal ) => // method invoked by the loop on each iteration { subtotal += j; //modify local variable return subtotal; // value to be passed to next iteration }, // Method to be executed when each partition has completed. // finalResult is the final value of subtotal for a particular partition. finalResult => Interlocked.Add( ref total, finalResult ) ); Console.WriteLine( "The total from Parallel.ForEach is {0:N0}", total );
IsInfinity
Console.WriteLine("IsInfinity(3.0 / 0) == {0}.", double.IsInfinity(3.0 / 0) ? "true" : "false");
dynamic Type
با استفاده از نوع dynamic می توان عملیات چک کردن نوع در زمان کامپایل را پشت سر گذاشت و در عوض این عملیات را به زمان اجرا، موکول داد.
نکته: نوع dynamic همانند نوع object در بسیاری از شرایط، یکسان رفتار میکند. اگرچه عملیاتهایی که شامل عبارتهایی از نوع dynamic هستند، یا نوع آن توسط کامپایلر بررسی میشوند و یا پذیرفته نمیشوند. کامپایلر اطلاعات مربوط به یک پردازش (روند) را یکجا بسته بندی میکند و این اطلاعات را بعداً در زمان اجرا ارزیابی میکند. به عنوان بخشی از این پردازش، متغیرهایی از نوع dynamic به متغیرهایی از نوع object کامپایل میشوند. بنابراین نوع dynamic فقط در زمان کامپایل وجود دارند (نه در زمان اجرا).
var i = 20; dynamic dynamicVariable = i; Console.WriteLine( dynamicVariable ); var stringVariable = "Example string."; dynamicVariable = stringVariable; Console.WriteLine( dynamicVariable ); var dateTimeVariable = DateTime.Today; dynamicVariable = dateTimeVariable; Console.WriteLine( dynamicVariable ); // The expression returns true unless dynamicVariable has the value null. if ( dynamicVariable is dynamic ) Console.WriteLine( "dynamicVariable variable is dynamic" ); // dynamic and the as operator. dynamicVariable = i as dynamic; // throw RuntimeBinderException if the associated object doesn't have the specified method. // The code is still compiling successfully. Console.WriteLine( dynamicVariable.ToNow1 );
همانطور که در مثال بالا مشاهده میکنید، شما میتوانید متغیرهایی از نوعهای مختلف را به یک شی از نوع dynamic اختصاص دهید. همچنین میتوانید برای بررسی یک متغیر که از نوع dynamic است یا خیر، از عملگر is استفاده کنید. اگر یک خصوصیت را که وجود ندارد، درخواست کنید (خط آخر مثال بالا)، خطای RuntimeBinderException پرتاب میشود.
ExpandoObject
dynamic sampleObject = new ExpandoObject(); sampleObject.FirstName = "Vahid"; sampleObject.LastName = "Mohammad Taheri"; sampleObject.Age = "28"; sampleObject.TestRemoveProperty = DateTime.Now; sampleObject.AsString = new Action( () => Console.WriteLine( "{0} {1} is {2} years old.", sampleObject.FirstName, sampleObject.LastName, sampleObject.Age ) ); sampleObject.AsString();
( (IDictionary< String, Object >)sampleObject ).Remove( "TestRemoveProperty" );
کتابخانه intence
مقایسهای بین REST و GraphQL
How does a developer find a new tool to add to their stack? There’s no single answer, but most will tell you that technical content is part of that journey. Certainly, documentation is crucial to developer experience. But more often than not, the first piece of content they’ll discover is a helpful resource returned as search results or shared from another dev. Your goal is simple: be that resource.