text
stringlengths
46
37.3k
title
stringlengths
12
162
C_sharp : When I remove Ldstr `` a '' and Call Console.WriteLine ( before Ret ) , the code runs fine , otherwise an InvalidProgramException is thrown upon invocation . Does this mean that an empty evaluation stack is required ? <code> class Program { delegate void Del ( ) ; static void Main ( string [ ] args ) { Dynami...
Is an empty evaluation stack required before an exception block ?
C_sharp : or <code> db.Albums.FirstOrDefault ( x = > x.OrderId == orderId ) db.Albums.FirstOrDefault ( x = > x.OrderId.Equals ( orderId ) )
Linq to SQL - what 's better ?
C_sharp : I have the next function : I inserted the print function for analysis.If I call the function : It return true since 5^2 equals 25.But , if I call 16807 , which is 7^5 , the next way : In this case , it prints ' 7 ' but a == ( int ) a return false.Can you help ? Thanks ! <code> static bool isPowerOf ( int num ...
C # isPowerOf function
C_sharp : Can someone explain the following piece of codeIt assigns 32 to y <code> int x = 45 ; int y = x & = 34 ;
How does this C # code snippet work ?
C_sharp : While testing an application , I ran a into strange behaviour . Some of the tests use impersonation to run code as a different user , but they would always hang , never complete.After some investigation , the problem was narrowed down to the use of mutexes . Originally , we used our own impersonation code bas...
Mutex creation hangs while using impersonation
C_sharp : I have a LINQ statement which is adding up the values of multiple columns , each beginning with 'HH ' although there are other columns available : Is there any way to tidy this up ? I have to do lots of variations of this ( in different methods ) so it would clear out a lot of 'fluff ' if it could be.Also I '...
Ugly LINQ statement , a better way ?
C_sharp : While looking at the Implementation of List.AddRange i found something odd i do not understand.Sourcecode , see line 727 ( AddRange calls InsertRange ) Why doest it Copy the collection into a `` temp-array '' ( itemsToInsert ) first and then copies the temp array into the actual _items-array ? Is there any re...
List < T > .AddRange / InsertRange creating temporary array
C_sharp : I have an overload method - the first implementation always returns a single object , the second implementation always returns an enumeration.I 'd like to make the methods generic and overloaded , and restrict the compiler from attempting to bind to the non-enumeration method when the generic type is enumerab...
an I prevent a specific type using generic restrictions
C_sharp : I always thought it worked fine both ways . Then did this test and realized it 's not allowed on re-assignments : works fine but not : Any technical reason for this ? I thought I would ask about it here , because this behavior was what I expected intuitively . <code> int [ ] a = { 0 , 2 , 4 , 6 , 8 } ; int [ ...
Why are collection initializers on re-assignments not allowed ?
C_sharp : I am wondering if there is some way to optimize the using statement to declare and assign its output together ( when it is a single value ) .For instance , something similar to the new way to inline declare the result variable of an out parameter.Thanks for your input . <code> //What I am currently doing : st...
C # using statement with return value or inline declared out result variable
C_sharp : The following VB.NET code works : The following C # code fails to compile : The LearnerLogbookReportRequest is declared as : Error : Why is the C # version failing to compile ? <code> Dim request As Model.LearnerLogbookReportRequest = New Model.LearnerLogbookReportRequestrequest.LearnerIdentityID = Convert.To...
Why does my code compile in VB.NET but the equivalent in C # fails
C_sharp : Hi my head is boiling now for 3 days ! I want to get all DNA encodings for a peptide : a peptide is a sequence of amino acids i.e . amino acid M and amino acid Q can form peptide MQ or QMDNA encoding means there is a DNA code ( called codon ) for each amino acid ( for some there are more than one code i.e . a...
how to get all dna encoding for peptide in c #
C_sharp : I want to prohibit reentrancy for large set of methods.for the single method works this code : This is tedious to do it for every method.So I 've used StackTrace class : It works fine but looks more like a hack.Does .NET Framework have special API to detect reentrancy ? <code> bool _isInMyMethod ; void MyMeth...
Does framework have dedicated api to detect reentrancy ?
C_sharp : I 'm newer to C # and have just discovered how to use yield return to create a custom IEnumerable enumeration . I 'm trying to use MVVM to create a wizard , but I was having trouble figuring out how to control the flow from one page to the next . In some cases I might want a certain step to appear , in others...
Wizard navigation with IEnumerable / yield return
C_sharp : Ok , this is a little weird . Ignore what I am trying to do , and look at the result of what happens in this situation.The Code : The Situation : The line numbers = rawNumbers.Split ( ' , ' ) .Cast < int > ( ) ; appears to work , and no exception is thrown . However , when I iterate over the collection , and ...
Did I really just put a string data type into an IEnumerable < int >
C_sharp : I migrated an WebAPI from FullDotnet ( 4.6 ) to .Net Core 2.0 and I 'm having this issue in my Data Layer using Dapper.My code : Strange Behavior : The solution Builds and WORKThe `` error '' who VisualStudio highlight is : Argument type 'lambda expression ' is not assignable to parameter type 'System.Func ` ...
Why does Visual Studio report a lambda error in a working WebAPI code on .Net Core ?
C_sharp : I 've read this answer and understood from it the specific case it highlights , which is when you have a lambda inside another lambda and you do n't want to accidentally have the inner lambda also compile with the outer one . When the outer one is compiled , you want the inner lambda expression to remain an e...
Why would you quote a LambdaExpression ?
C_sharp : We have a web api with the following resource url.now there are some books which contains names with ampersand ' & ' and when a request is made for such names , we are receiving below errorURL used : Error : A potentially dangerous Request.Path value was detected from the client ( & ) We tried passing or usin...
error when url resource contains ampersand
C_sharp : I have a RGB image ( RGB 4:4:4 colorspace , 24-bit per pixel ) , captured from camera . I use Gorgon 2D library ( build base on SharpDX ) to display this image as a texture so i have to convert it to ARGB . I use this code ( not my code ) to convert from RGB camera image to RGBA.Then convert RGB to RGBA like ...
How to convert RGB camera image to ARGB format of SharpDX ?
C_sharp : Anyone can elaborate some details on this code or even give a non-Linq version of this algorithm : <code> public static IEnumerable < IEnumerable < T > > Combinations < T > ( this IEnumerable < T > elements , int k ) { return k == 0 ? new [ ] { new T [ 0 ] } : elements.SelectMany ( ( e , i ) = > elements .Ski...
How to understand the following C # linq code of implementing the algorithm to return all combinations of k elements from n
C_sharp : I have seen people use a couple of different way of initializing arrays : or another way , also called initializing is : What is the best way , and what is the major difference between both ways ( including memory allocation ) ? <code> string [ ] Meal = new string [ ] { `` Roast beef '' , `` Salami '' , `` Tu...
Whats the difference between Declaring a variable ( as new ) and then initializing it and direct initializing it ?
C_sharp : I 'm looking to implement some algorithm to help me match imperfect sequences.Say I have a stored sequence of ABBABABBA and I want to find something that 'looks like ' that in a large stream of characters.If I give my algorithm the allowance to have 2 wildcards ( differences ) , how can I use Regex to match s...
Regex to find 'good enough ' sequences
C_sharp : I 'm working on my final year project . In which : I have Login and Signup forms on one page ( WebForm ) : When user click on anchor Sign Up the DropDown ddlType ( hides ) and TextBoxes - txtCustName , txtEmail and txtConfirmPassword ( Displays ) in Javascript client side : Login Form : -And when user click o...
How to stop on the Sign Up Form when web page performs Postback ?
C_sharp : I 'm having problem with finding most common group of integers among int [ x,6 ] array , where x < = 100000 . Numbers are between 0 and 50.eg input . ( N = 2 ) output : Attached code I tried . Now I understand it does n't work , but I was asked me to post it . I 'm not just asking help without even trying . <...
How to find a group of integers ( N ) amongst records , that contains 6 integers
C_sharp : I found this code snippet on SO ( sorry I do n't have the link to the question/answer combo ) This confuses me because FileAttributes.Directory is on both sides of the ==.What does the & do in this case ? I 'm not sure how to read this line of code . I 'm trying to evaluate whether a path string is a file or ...
How does this C # operator work in this code snippet ?
C_sharp : I 've got a controller method : Now , I 'd like to test this.This throws a RuntimeBinderException saying that Calculated is not defined . Is there any way to achieve this ? UPDATEFollowing Jons ' advice , I used InternalsVisibleTo to befriend my test assembly . Everything works fine . Thank you Jon . <code> p...
Using dynamic in C # to access field of anonymous type - possible ?
C_sharp : Is there a more efficient way of doing the following , something just feels wrong about it ? I 'm looking for the most time efficient way of logging logarithmically.Update : Here are my micro benchmark tests.Method1 : Übercoder 's way with keep up with stateMethod2 : My way with the big switch statementMethod...
Logging logarithmically 1 , 10 , 100 , 1000 , etc
C_sharp : I want to find the closest transaction amount which is closest ( which should be > = transaction amount ) or equal to single transaction amount of the given number , but it should be minimum amount . there will be many combination of data which is > = given number but out of those combination I want minimum t...
Get closest value from list by summation or exact single value using C #
C_sharp : I have a method that is defined like such : I would like to do something like : My challenge is , I 'm not sure how to detect whether my propertyValue is a nullable bool or not . Can someone tell me how to do this ? Thank you ! <code> public bool IsValid ( string propertyName , object propertyValue ) { bool i...
Detecting nullable types in C #
C_sharp : I have started to understand that I do not understand what is going on . There is the following behavior in C # : It will print public void Method ( B a ) instead of public void Method ( D a ) It 's surprising . I suppose that the reason of this behavior is implementation of methods table . CLR does not searc...
Overloading methods in inherited classes
C_sharp : My code below finds all prime numbers below number by creating a list of primes and checking to see if the next potential prime is evenly divisible by any primes in the list.I 'm trying to learn the ins and outs of yield return . Right now I have a List < int > primes that I use inside the function . But I 'm...
Can you access the IEnumerable as you are yield returning it ?
C_sharp : I am trying to understand how async/await keywords works . I have a textblock on a WPF window bind to a TextBlockContent string property and a button which trigger on click ChangeText ( ) .Here is my code : From my readings , I understood that ConfigureAwait set to false would allow me to specify that I do no...
Why am I still on the Main Thread when I specified ConfigureAwait ( false ) ?
C_sharp : I 'm attempting to grab a device handle on the Synaptics Touchpad using the Synaptics SDK , specifically using methods in the SYNCTRLLib . However , the SYNCTRL method failed to find it , returning -1.Syn.cs : Program.cs <code> using System ; using System.Collections.Generic ; using System.Linq ; using System...
Synaptics SDK ca n't find device
C_sharp : I 'm in a little bit of a bind . I 'm working with a legacy system that contains a bunch of delimited strings which I need to parse . Unfortunately , the strings need to be ordered based on the first part of the string . The array looks something likeSo I 'd like the array to order to look likeI thought about...
How to numerically order array of delimited strings in C #
C_sharp : I 'm facing a deadlock-issue in a piece of code of mine . Thankfully , I 've been able to reproduce the problem in the below example . Run as a normal .Net Core 2.0 Console application.What I 'd expect is the complete sequence as follows : However , the actual sequence stalls on the Thread.Join call : Finally...
What 's causing a deadlock ?
C_sharp : I have a class Player that implements ICollidable . For debugging purposes I 'm just trying to pass a bunch of ICollidables to this method and do some special stuff when it 's the player . However when I try to do the cast to Player of the ICollidable I get an error telling me that ICollidable does n't have a...
Why is this cast from interface to class failing ?
C_sharp : I have simple ASP.NET Core WebApi with modeland endpointWhen I make a POST request with bodyorthen model.Value == trueHow to avoid this ? I need some error in this case , because 7676 is not the Boolean value.I found this question and this , but solution is not fit for me , because I have a many models in dif...
Avoid bind any number to bool property
C_sharp : I recently ran into an interesting issue with changing CASE statements to ISNULL functions in TSQL . The query I was working with is used to get some user attributes and permissions for a website I work on . Previously the query had a number of CASE statements similar to the following : NOTE : a.column1 in th...
ISNULL vs CASE Return Type
C_sharp : All C # beginners know that class is a reference type and struct is a value one.Structures are recommended for using as simple storage.They also can implement interfaces , but can not derive from classes and can not play a role of base classes because of rather `` value '' nature.Assume we shed some light on ...
C # hack : assignment to `` this ''
C_sharp : I have a condition with two value . if the condition equal to 0 it return Absent and if equal to 1 it returns present.now I want to add the third value into my condition . if the condition equal to 3 it returns Unacceptable absent.this is my conditions with two value : how can I change the condition ? <code> ...
how can I change this condition to that I want
C_sharp : Description : I am modifying the ASP.NET Core Web API service ( hosted in Windows Service ) that supports resumable file uploads . This works fine and resumes file uploads in many failure conditions except one described below.Problem : When the service is on ther other computer and the client is on mine and I...
Web API service hangs on reading the stream
C_sharp : I have the following code : Why does n't the marked line compile ? Does it have something to do with return type not being part of the signature ? But the third line does compile , which makes me guess the compiler turns it into something similiar to the second line ... <code> public static class X { public s...
C # Infer generic type based on passing a delegate
C_sharp : In my templates I 've got these repeating blocks of content which I want to abstract to a single component : Normally I would use a razor partial view for this , and pass it some variables . However in this case that would mean passing big chunks of html as variables , which does n't seem wise.I 've found thi...
How can I abstract this repeating pattern in ASP.NET MVC 5 ?
C_sharp : I get an exception System.ArrayTypeMismatchException : Source array type can not be assigned to destination array type for this code snippet : Then I resort to Jon 's answer in Why does `` int [ ] is uint [ ] == true '' in C # , it told me that because of GetArray ( ) returns an Array , the conversion was pos...
Exception for calling ToList ( ) after conversion from uint [ ] to int [ ] in C #
C_sharp : I ran across this issue today and I 'm not understanding what 's going on : Output : I know Cast ( ) is going to result in deferred execution , but it looks like casting it to IEnumerable results in the deferred execution getting lost , and only if the actual implementing collection is an array.Why is the enu...
Why Does an Array Cast as IEnumerable Ignore Deferred Execution ?
C_sharp : I do n't understand why the following compiles : My knowledge says that a is assignable to b only if a is of type b or a extends/implements b . But looking at the docs it does n't look like StringValues extends string ( string is a sealed class , therefore it should n't be even possible ) .So I assume this is...
Why is StringValues assignable to String
C_sharp : In C # I am working with large arrays of value types . I want to be able to cast arrays of compatible value types , for example : I want bitmap2 to share memory with bitmap1 ( they have the same bit representations ) . I do n't want to make a copy.Is there a way to do it ? <code> struct Color { public byte R ...
Casting of arrays in C #
C_sharp : The following code is illegal : The way things should be done is obviously : But the following is also allowed ( I did n't know this and stumbled upon it by accident ) : I guess the compiler verifies that all fields of the struct have been initialized and therefore allows this code to compile . Still I find i...
Confused with little used Value Type initialization
C_sharp : I 've read the answers for Class with indexer and property named `` Item '' , but they do not explain why can I have a class with multiple indexers , all of them creating Item property and get_Item/set_Item methods ( of course working well , as they are different overloads ) , but I can not have an explicit I...
`` Item '' property along with indexer
C_sharp : Given this example code : Which returns : -1What does the first arrow operator mean ? By specification it does not look like an expression body or a lambda operator.Is there any reference in the C # language specification about this usage ? <code> enum op { add , remove } Func < op , int > combo ( string head...
What does the first arrow operator in this Func < T , TReturn > mean ?
C_sharp : In Haskell , we have the filterM function . The source code for it is : Translating from do notation : To the best of my understanding , > > = on lists in Haskell and SelectMany on IEnumerablein C # are the same operation and so , this code should work just fine : But it does n't work . Can anyone point me to...
Monadic Programming in C #
C_sharp : I have just noticed that the following code returns true : I have read the Mathf.Approximately Documentation and it states that : Approximately ( ) compares two floats and returns true if they are within a small value ( Epsilon ) of each other.And Mathf.Epsilon Documentation states that : anyValue + Epsilon =...
Is Mathf.Approximately ( 0.0f , float.Epsilon ) == true its correct behavior ?
C_sharp : I have a mock being created like this : The intellisense for the Setup method says this : `` Specifies a setup on the mocked type for a call to a void returning method . `` But the mocked method p.GetBytes ( ) does not return void , it returns a byte array . Alternatively another Setup method is defined as Se...
Moq confusion - Setup ( ) v Setup < > ( )
C_sharp : I 'm trying to deserialize a part of a json file that represents this class . where two properties are optional : Text and Parameters . I 'd like them to be populated with default values.The problem is that I can not figure out how to make it work for both of them . If I use the DefaultValueHandling.Populate ...
How can I populate an optional collection property with a default value ?
C_sharp : I am writing a helper method for conveniently setting the Name of a Thread : It 's working as intended . ReSharper , however , claims that the condition is always false and the corresponding code is heuristically unreachable . That 's wrong . A Thread.Name is always null until a string is assigned.So , why do...
Why does ReSharper think that `` thread.Name == null '' is always false ?
C_sharp : Imagine that I have a several Viewer component that are used for displaying text and they have few modes that user can switch ( different font presets for viewing text/binary/hex ) . What would be the best approach for managing shared objects - for example fonts , find dialog , etc ? I figured that static cla...
Managing of shared resources between classes ?
C_sharp : When you were a kid , did you ever ask your parents how to spell something and they told you to go look it up ? My first impression was always , `` well if could look it up I wouldnt need help spelling it '' . ( yeah yeah I know phonetics ) ... anyway , I was just looking at some code and I found an example l...
Learning by example - terminology ( ? , : , etc )
C_sharp : I have a problem with some overloaded methods and I will try to give a simple implementation of it.So here is a class contains two methods below : and this my entity : Here is where I 'm utilizing it : The problem is that I just have two methods with same name and different arguments so , based on OOP polymor...
Misunderstanding of .NET on overloaded methods with different parameters ( Call Ambiguous )
C_sharp : I have an optimization problem where I have 5 variables : A , B1 , B2 , C1 , C2 . I am trying to optimize these 5 variables to get the smallest root sum square value I can . I have a few optimization techniques that are working ok , but this one in particular is giving me some trouble.I want to explore all 32...
How do I iterate between 32 binary options ?
C_sharp : During an research the purpose of this reassignment possibility with structs I ran into following puzzle : Why it is needed to do this = default ( ... ) at the beginning of some struct constructor . It 's actually zeroes already zeroed memory , is n't it ? See an example from .NET core : <code> public Cancell...
What the purpose of this = default ( ... ) in struct constructor ?
C_sharp : I understand that the following C # code : compiles to : But what does it mean that it compiles to that ? I was under the impression that C # code compiles directly into CIL ? <code> var evens = from n in nums where n % 2 == 0 select n ; var evens = nums.Where ( n = > n % 2 == 0 ) ;
C # Compiled to CIL
C_sharp : Here is the code extracted of the SingleOrDefault function : I 'm wondering to know if there is any reason why after finding more than one element in the loop , there is no break statement to prevent looping the rest of the list . In anyways , an error will occurs . For a big list where more than one item is ...
Optimization in the SingleOrDefault function of Linq
C_sharp : Just out of curiosity , why does the compiler treat an unconstrained generic type any differently than it would typeof ( object ) ? In the above , casting `` T thing '' to Bar results in a compiler error . Casting `` object thing '' to Bar however is something the compiler lets me do , at my own risk of cours...
The rules of generics and type constraints
C_sharp : I have a question regarding await/async and using async methods in slightly different scenarios than expected , for example not directly awaiting them . For example , Lets say I have two routines I need to complete in parallel where both are async methods ( they have awaits inside ) . I am using await TAsk.Wh...
await/async and going outside the box
C_sharp : I have the following enum defined . I have used underscores as this enum is used in logging and i do n't want to incur the overhead of reflection by using custom attribute.We use very heavy logging . Now requirement is to change `` LoginFailed_InvalidAttempt1 '' to `` LoginFailed Attempt1 '' . If i change thi...
How to change enum definition without impacting clients using it in C #
C_sharp : I am looking to setup something very similar to transaction scope which creates a version on a service and will delete/commit at the end of scope . Every SQL statement ran inside the transaction scope internally looks at some connection pool / transaction storage to determine if its in the scope and reacts ap...
Transaction scope similar functionality
C_sharp : I get a red line under my await in my code saying : The type arguments for method 'TaskAwaiter < TResult > System.WindowsRuntimeSystemExtensions.GetAwaiter < TResult > ( this Windows.Foundation.IAsyncOperation 1 ) ' can not be inferred from the usage . Try specifying the type arguments explicitlyThough the co...
TaskAwaiter can not be inferred from the usage
C_sharp : I have an Azure Function with a service bus trigger : In 99.9 % of the invocations , the trigger successfully resolves to a subscription on Azure Service Bus . But sometimes , I see the following error in my log : It seems that the service bus trigger can not resolve the connection variable from settings.I tr...
Connection string is sometimes not available in ServiceBusTrigger
C_sharp : Why can´t we raise an event with a custom implementation , while it is possible without them ? See this code : You see both events are declared within my class . While target.AnotherEvent ( ... ) compiles just fine , target.MyEvent ( ... ) does not : The Event MyEvent can only appear on the left hand side of ...
Why can´t we raise event with accessors ?
C_sharp : I 'm having hard time understanding the following C # code . This code was taken from Pro ASP.NET MVC 2 Framework by Steven Sanderson . The code esentially creates URLs based on a list of categories . Here 's the code : A lot of stuff is going on here . I 'm guessing it 's defining a function that expects two...
Why did they use this C # syntax to create a list of links in ASP.NET MVC 2 ?
C_sharp : I have following code : and use it as following : Is there any way to define something like this : I used Expression < Func < T , bool > > to use it as where clause in my linq to entities query ( EF code first ) . <code> public class MyClass < T > { Expression < Func < T , bool > > Criteria { get ; set ; } } ...
Define part of an Expression as a variable in c #
C_sharp : Can a static function in a static class which uses yield return to return an IEnumerable safely be called from multiple threads ? Will each thread that calls this always receive a reference to each object in the collection ? In my situation listOfFooClassWrappers is written to once at the beginning of the pro...
Is yield return reentrant ?
C_sharp : Recently I decided to investigate the degree of randomness of a globally unique identifier generated with the Guid.NewGuid method ( which is also the scope of this question ) . I documented myself about pseudorandom numbers , pseudorandomness and I was dazzled to find out that there are even random numbers ge...
Estimating the digits occurrence probability inside a GUID
C_sharp : i 'm trying to print `` p '' to the screen every second.when I run this : it does n't print at all.But when I run this : Its printing without waiting at all . Can somebody please explain this to me and suggest a fix ? <code> while ( true ) Thread.Sleep ( 1000 ) ; Console.WriteLine ( `` p '' ) ; while ( true )...
waiting for a second every time in a loop in c # using Thread.Sleep
C_sharp : I have been playing with WPF for a while and I came across an interesting thing . When I bind DateTime object to the Label 's content then I see locally formatted representation of the date . However , when I bind to the TextBlock 's Text property then I actually see English one.It seems that TextBlock is usi...
Culture difference between Label and TextBlock
C_sharp : I have a method I used in MvvmCross 4.x that was used with the NotificationCompat.Builder to set a PendingIntent of a notification to display a ViewModel when the notification is clicked by the user . I 'm trying to convert this method to use the MvvmCross 5.x IMvxNavigationService but ca n't see how to setup...
How do I get PendingIntent using the MvvmCross 5 IMvxNavigationService ?
C_sharp : I 'm making a jquery clone for C # . Right now I 've got it set up so that every method is an extension method on IEnumerable < HtmlNode > so it works well with existing projects that are already using HtmlAgilityPack . I thought I could get away without preserving state ... however , then I noticed jQuery ha...
How to design my C # jQuery API such that it is n't confusing to use ?
C_sharp : I 'm quite new to Linq . I have something like this : This works fine but for obvious reasons I do n't want the split ( ) method to be called twice.How can I do that ? Thanks for all your responses : ) , but I can only choose one . <code> dict = fullGatewayResponse.Split ( ' , ' ) .ToDictionary ( key = > key....
Linq call a function only once in one statement
C_sharp : Let 's say there are these generic types in C # : and these concrete types : Now the definition of PersonRepository is redundant : the fact that the KeyType of Person is int is stated explicitly , although it can be deduced from the fact that Person is a subtype of Entity < int > .It would be nice to be able ...
Generic Type Inference in C #
C_sharp : I have the following sample code.According to MSDN : Exists property : true if the file or directory exists ; otherwise , false.Why Exists returns false after directory has been created ? Am I missing something ? <code> private DirectoryInfo PathDirectoryInfo { get { if ( _directoryInfo == null ) { // Some lo...
Creating Directory does n't update the Exists property to true
C_sharp : This is mostly academic - but I was looking at the implementation of Equals ( ) for ValueTypes . The source code is here : http : //referencesource.microsoft.com/ # mscorlib/system/valuetype.cs # 38The code that caught my eye was this : FastEqualsCheck ( ) is declared as follows : My understanding is that the...
How Can I Call FastEqualsCheck ( ) ?
C_sharp : I wanted to add a nice shadow to my borderless form , and the best way I found to do it with minimal performance loss is to use DwmExtendFrameIntoClientArea . However , this seems to be causing Windows to draw a classic title bar over the window , but it is non-functional ( ie . the glitch is merely graphical...
Prevent Win32 from drawing classic title bar
C_sharp : I find myself creating loads of the properties following the pattern : Is there an easy way to automate creating of these properties ? Usually I : type the field , including the readonly keywordSelect `` initialize from constructor parametersSelect `` encapsulate '' Is it possible to make it quicker ? <code> ...
How can I automate creating immutable properties with ReSharper ?
C_sharp : I just came across this weird 'behavior ' of the Garbage Collector concerning System.Threading.ThreadLocal < T > that I ca n't explain . In normal circumstances , ThreadLocal < T > instances will be garbage collected when they go out of scope , even if they are n't disposed properly , except in the situation ...
Memory leak when ThreadLocal < T > is used in cyclic graph
C_sharp : I know there 's a couple similarly worded questions on SO about permutation listing , but they do n't seem to be quite addressing really what I 'm looking for . I know there 's a way to do this but I 'm drawing a blank . I have a flat file that resembles this format : Now here 's the trick : I want to create ...
Split and join multiple logical `` branches '' of string data
C_sharp : To declare float numbers we need to put ' f ' for floats and 'd ' for doubles . Example : It is said that C # defaults to double if a floating point literal is omitted.My question , is what prevents a modern language like ' C # ' to 'DEFAULTS ' to the left hand side variable type ? After all , the compiler ca...
C # floating point literals : Why compiler does not DEFAULTS to the left hand side variable type
C_sharp : I was doing a refactoring of class and thought of moving 100 lines in a separate method . Like this : At calling method of Compiler throws exception : Readonly local variable can not be used as an assignment target for doc and mem.Edit : here only i adding content in pdf document in another method . so i need...
IDisposable objects as ref param to method
C_sharp : Very short question but I could n't find a solution on the web right now.Will 1 + 2 be performed during run- or compile-time ? Reason for asking : I think most people sometimes use a literal without specifying why it has been used or what it means because they do not want to waste a bit performance by running...
Are arithmetic operations on literals in C # evaluated at compile time ?
C_sharp : I have a WPF application with a number of comboboxes that tie together . When I switch comboboxx # 1 , combobox # 2 switches , etc.Here is the xaml for the 2 comboboxes : CboDivision gets populated at the beginning and doesnt need a reset . HEre is the code that calls the change in division , which should tri...
Clearing and refilling a bound combo box
C_sharp : The Stackoverflow API is returning an unexpected response when C # to create a HTTP GET request.If I paste http : //api.stackoverflow.com/1.1/users/882993 into the browsers address bar I get the correct JSON response : If I attempt to perform the same action in code : I get the response : <code> { `` total ''...
Stackoverflow API response format
C_sharp : Why does the OR operator in vb and C # give different results.http : //dotnetfiddle.net/wC9AgGhttp : //dotnetfiddle.net/g4tLQ9 <code> Console.WriteLine ( 0x2 | 0x80000000 ) ; output 2147483650 Console.WriteLine ( & H2 Or & H80000000 ) output -2147483646
C # vs VB.NET bitwise OR
C_sharp : There 's far too much code to paste into a question here so I have linked to a public gist.https : //gist.github.com/JimBobSquarePants/cac72c4e7d9f05f13ac9I have an animated gif encoder as part of an image library that I maintain and there is something wrong with it.If I attempt to upload any gif that have be...
Animated gif encoder error
C_sharp : Given the output of query : What would you consider the neatest way to detect if a file is in the queryResult ? Here is my lame try with LINQ : There must be an more elegant way to figure out the result . <code> var queryResult = from o in objects where ... select new { FileName = o.File , Size = o.Size } str...
Writing 'CONTAINS ' query using LINQ
C_sharp : According to the Constraints on Type Parameters ( C # Programming Guide ) documentation it says , and I quote : When applying the where T : class constraint , avoid the == and ! = operators on the type parameter because these operators will test for reference identity only , not for value equality . This is t...
Avoid == and ! = operators on generic type parameters , but can it compare with null ?
C_sharp : I have this simple code : This interface should be covariant on T , and i 'm using it this way : Note the constraint for T to implement IComposite.The synchronization method takes an IReader < IComposite > in input : The compiler tells me it can not convert from IReader < T > to IReader < IComposite > despite...
.NET Covariance
C_sharp : I happen to see a code something like this.When and why do we need this kind of dynamic type casting for parameters ? <code> function ( ( dynamic ) param1 , param2 ) ;
dynamic type casting in parameter in c #
C_sharp : Sometimes I want to add more typesafety around raw doubles . One idea that comes up a lot would be adding unit information with the types . For example , In the case like above , where there is only a single field , will the JIT be able to optimize away this abstraction in all cases ? What situations , if any...
Is a struct wrapping a primitive value type a zero cost abstraction in C # ?
C_sharp : Basically , I have keywords like sin ( and cos ( in a textbox , which I want to have behave like a single character.When I mention the entire string below it is referring to the group of characters ( for example `` sin ( `` ) Using sin ( as an example : If the caret was in this position ( behind the s ) : If ...
C # Make a group of characters in a textbox behave like one character
C_sharp : When using C # Strongnames on DLLs and using the InternalsVisibleTo tags andwhen the public key uses SHA256 ( or SHA512 ) We 're noticing that the compile process fails as if the InternalsVisibleTo tags were never even declared . The error we get is MyInternalClass is inaccessible due to its protection level ...
StrongNaming with InternalsVisibleTo tag fails when SHA256 used
C_sharp : I have a frustrating problem with a bit of code and do n't know why this problem occurs . When running without Code optimization then the result is as expected . _cursorLeft and left as far as _cursorTop and top are equal.But when I run it with Code optimization both values _cursorLeft and _cursorTop become b...
C # Code optimization causes problems with Interlocked.Exchange ( )