text
stringlengths
46
37.3k
title
stringlengths
12
162
C_sharp : In the sample code below I get the following exception when doing db.Entry ( a ) .Collection ( x = > x.S ) .IsModified = true : System.InvalidOperationException : 'The instance of entity type ' B ' can not be tracked because another instance with the key value ' { Id : 0 } ' is already being tracked . When at...
Unexpected InvalidOperationException when trying to change relationship via property default value
C_sharp : I found in legacy code following line : What does [ , ] mean here ? <code> protected bool [ , ] PixelsChecked ;
bool [ , ] - What does this syntax mean in c # ?
C_sharp : Is there a generally-accepted best practice for creating an event handler that unsubscribes itself ? E.g. , the first thing I came up with is something like : To say that this feels hackish/bad is an understatement . It 's tightly coupled with a temporal dependency ( HandlerToUnsubscribe must be assigned the ...
Am I using the right approach to monitor the tasks I want to perform when a handle is created ?
C_sharp : The `` using '' construct looks incredibly handy for situations that require both beginning and separated end parts . Quick example to illustrate : The beginning part is defined as the constructor , the end part is the Dispose method.However despite of being attractive this construct has a serious caveat that...
`` using '' construct and exception handling
C_sharp : In .net fx i can doBut when looking at .net core or .net standard there is no more a culture parameter that can be passed . There is only string.ToLower ( ) and string.ToLowerInvariant ( ) Should the culture just be ommitted ? But should n't then there be issues when the culture of the string is not the curre...
.net core / standard string.ToLower ( ) has no culture parameter
C_sharp : I 'm trying to generate a bit pattern ( repetitive strings ) and export into a text file , Here 's my code : Result : Now if I change the loop value to `` 20 '' , Result : I get this funny little rectangle boxes , could somebody please suggest me , what am I doing wrong here ? ? Many thanks for your time.. : ...
How to generate repetitive bit pattern ( strings ) & export into text file ?
C_sharp : Trying with a Diagnostic and a CodeFix to make a code who transform that : Into : Already done the diagnostic ( it works ) : Edit : I 've made some change.Now the incrementating is always recognized . The program go in the CodeFix , but my ReplaceToken with a SyntaxFactory do n't work . ( It 's now only for `...
Roslyn C # incrementing change
C_sharp : Given a collection of Tasks : I would like to process the results of GetPricesAsync ( ) in whatever order they arrive . Currently , I 'm using a while loop to achieve this : Is this a problem that can be solved more elegantly using Rx ? I tried to use something like the code below but got stuck because somewh...
How to turn a list of Tasks into an Observable and process elements as they are completed ?
C_sharp : Im not sure because in Java getter/setter are looking a little bit different but whats the `` c # way '' to code this stuff ? Option a. ) b. ) c . ) Ok there are some examples . What would look better ? Should I write all the private variable declarations first then the properties or should I group my variabl...
How should I use Properties in C # ?
C_sharp : In our ASP.Net MVC 3 application we 're getting truncated strings on our forms when the string value contains a double-quote.For example , given a textbox : If the user enters the string : 'Hampshire '' County ' , when rendering the value back out to the form , only the string 'Hampsire ' is displayed . If I ...
Truncated strings with TextBoxFor
C_sharp : I was just reading an SO question on Python , and noticed the lack of parentheses in a for-loop . Looked nice to me , then I wondered : why does C # require them ? For example , I currently need to write : andSo I am wondering why I ca n't write : Is there a syntactic ambiguity in that statement that I am una...
Why does C # require parens around conditionals ?
C_sharp : I have an array consisting of following elements : The real object that i try to flatten is from importing data into array of arrays from CSV and then joining it on values of fields : I want to flatten that array of strings to get : I already have an solution that does that in loop , its not so performance-wi...
How do I flatten an array of arrays ?
C_sharp : I am writing code that interfaces with an external API that I can not change : It 's important that I call the correct overloaded method when reading data into buffer , but once the data is read in , I will process it generically . My first pass at code that does that was : C # , though , wo n't convert from ...
Is it possible to force an external class to call a specialized overload when the calling class is , itself , generic ?
C_sharp : The code below produces this error in Visual Studio 2012 ; `` A local variable named ' x ' can not be declared in this scope because it would give a different meaning to ' x ' , which is already used in a 'child ' scope to denote something else '' However . When modified as below I get this error ; `` The nam...
For loop counter variable scope seems to have a dual personality ?
C_sharp : Im working on an existing Windows Service project in VS 2013.I 've added a web API Controller class I cant remember now if its a ( v2.1 ) or ( v1 ) controller class ... .Anyway I 've called it SyncPersonnelViaAwsApiControllerIm trying to call it from a AWS lambda ... so If I call the GETwith const req = https...
can use API GET but not API POST
C_sharp : Given that I have three tables , Vehicles , Cars , Bikes . Both Cars and Bikes have a VehicleID FK that links back to Vehicles.I want to count all vehicles that are cars like this.However , this will give me ALL the rows of vehicles and put null in the rows where the vehicle type is Bikes.I 'm using linqpad t...
linq to sql : specifying JOIN instead of LEFT OUTER JOIN
C_sharp : I 've created a user control in a Windows Application C # 3.5 and it has a number of properties ( string , int , color etc ) . These can be modified in the properties window and the values are persisted without problem.However I 've created a property likeThe properties dialog allows me to add and remove thes...
.Net WinForm application not persisting a property of type List < MyClass >
C_sharp : During a demo I saw a piece of test code where the developer had pasted an url in the code . And when the developer build the application everything worked , but we where all very curious why the compiler accepted the url as a line.Why does the code above build ? Does the compiler treat the line as a comment ...
Url in code not breaking build
C_sharp : In my Word add-in , I have a Word Document object which contains a particular Section . In this Section , I append a Shape : My issue is that some Word document templates have images or other things that appear over top of my shape . Originally , I thought that setting the Z order would be enough to fix this ...
Making a Shape top-most
C_sharp : I would like to be able to write the following in a LINQ query : to use this code , I have the following method : How do I write this method so that the query stated above would work ? <code> from item in listcollate by item.Propertyselect item ; public static IEnumerable < T > CollateBy < T , TKey > ( this I...
Extend the options of LINQ
C_sharp : I am drawing a rectangle in the paint method of a control . There is a zoom factor to consider , e.g . each positive MouseWheel event causes the control to repaint and then the rectangle gets bigger . Now I am drawing a string inside this rectangle , but I could n't figure out how to relate the font size of t...
Dynamic font size to draw string inside a rectangle
C_sharp : I have a system that displays entries ordered by one of three fields , the most popular Today , This Week and This Month . Each time an entry is viewed the score is incremented by 1 thus changing the order.So if entry 1 is new and viewed 10 times today its scores will be : The Current SolutionAt the moment I ...
Popular Today , This Week , This Month - Design Pattern
C_sharp : I have a Visual Studio 2008 C # .NET 3.5 project where a class listens for an event invocation from another class that is multithreaded . I need to ensure that my event only allows simultaneous access to a maximum of 10 threads . The 11th thread should block until one of the 10 finishes.I do not have control ...
A function that only permits N concurrent threads
C_sharp : People here are using visual studio for performance testing . Now there are some small issues with some javascript parts : they are not able to check the performance of the javascript part with visual studio web-performance testing.I never used visual studio performance test , so I really have no idea how to ...
Read JS variable in C # / Forwarding JS variable to visual studio performance test ?
C_sharp : I have come across some unit tests written by another developer that regularly use an overloaded version of Assert.AreEqual like so : stringParamX is set within the unit test and stringparamY will be the result from the system under test.It is possible hat this code may be ported to other countries and these ...
When to pass Culture when comparing strings using Assert.AreEqual ( ) in C #
C_sharp : I use LINQ-SQL as my DAL , I then have a project called DB which acts as my BLL . Various applications then access the BLL to read / write data from the SQL Database.I have these methods in my BLL for one particular table : All pretty straight forward I thought.Get_SystemSalesTaxListByZipCode is always return...
What 's the difference between these LINQ queries ?
C_sharp : Problem : Displaying large amounts of data in a scrollable area has horrible performance and/or User eXperience.Tried : Basically set a DataTemplate in a ListBox to show a grid of populated data with the VirtualizationMode set to Recycle and a fixed height set on the ListBox iteself . Something like the examp...
Virtualization Performance Issue with Large Scrollable Data SL4
C_sharp : I have a C # web api which I use to access an F # library . I have created a DU of the types I want to return and use pattern matching to choose which is return back to the c # controller . In the C # controller how do I access the data of the type which is return from the function call to the F # library ? C...
Working with F # types in C #
C_sharp : I 'm working on a neural networks project and I have 2 classes like this : When I try to create network and display it 's `` contents '' : When I run that code - I 'm getting something like this ( all weights are identical ) : When I saw it - I tried to debug and find my mistake . However , when I put breakpo...
Very weird - code ( with Random ) works different when I use breakpoint
C_sharp : When we connect to a database in ASP.NET you must specify the appropriate connection string . However most other instances where data is to be specified is done within an object.For example why could n't we have connection objects such as : which is far better than some key/value string : Data Source=myServer...
Why do we need connection strings ?
C_sharp : I 'm wondering if someone else can come up with a better way of simplifying relative URLs on either the basis of System.Uri or other means that are available in the standard .NET framework . My attempt works , but is pretty horrendous : This gives , for example : The problem that makes this so awkward is that...
Simplify a relative URL
C_sharp : I have some code in a WPF application that looks like this : The dispose method is never getting explicitly called so the destructor calls it . It seems like in this case the object would be destroyed before the delegate in the BeginInvoke fires on the UI thread . It appears to be working though . What is hap...
Calling BeginInvoke from a destructor
C_sharp : Is there a performance/memory usage difference between the two following property declarations , and should one be preferred ? Also , does the situation change if the Boolean is replaced with a different immutable value ( e.g . string ) ? <code> public bool Foo = > true ; public bool Foo { get ; } = true ;
Get-only property with constant value , auto-property or not ?
C_sharp : So I 've been going through various problems to review for upcoming interviews and one I encountered is determining whether two strings are rotations of each other . Obviously , I 'm hardly the first person to solve this problem . In fact , I did discover that my idea for solving this seems similar to the app...
How to generalize my algorithm to detect if one string is a rotation of another
C_sharp : The Code PartImage Unfortunately this menu does not appear after I transform html file to aspx , what am I missing ? Do I missing something to enable ? Since the order of index.html file is absolutely the same with index.aspx , just I want to see the js powered menu . please help ! I just released that when I...
Covered from html to aspx page , but the menus disappeared , why ?
C_sharp : C # does n't allow lambda functions to represent iterator blocks ( e.g. , no `` yield return '' allowed inside a lambda function ) . If I wanted to create a lazy enumerable that yielded all the drives at the time of enumeration for example , I 'd like to do something likeIt took a while , but I figured out th...
How to create an IEnumerable to get all X lazily in a single statement
C_sharp : In this piece of codeWhy does my Javascript recognize Model.IntegerParameter correctly but Model.StringParameter as null ? I am sure it has data on it as I check the response and it shows like thisMy View model is really simple and it looks like thisHow do I fix this ? Added InfoI tried changing the second pa...
String Parameter in AjaxOption null on Submit but showing in Response
C_sharp : I am running a search algorithm which is fed at the start with a single seed . From this point on I expect the algorithm to behave in a deterministic fashion , which it largely does . I can largely verify this by looking at the 10,000th step , 20,000 step and seeing they are identical . What I am seeing diffe...
Why might my C # computation time be non-deterministic ?
C_sharp : So the question is in the header.What NHibernate users can do : How to mimic such behavior in EF 4 ? <code> var q1 = Source.Companies.ToFuture ( ) ; var q2 = Source.Items.ToFuture ( ) ; var q3 = Source.Users.ToFuture ( ) ; var compoundModel = new CompoundModel ( q1 , q2 , q3 ) ; // All data obtained in single...
Does an analog of the NHibernate.ToFuture ( ) extension method exist in the Entity Framework ?
C_sharp : I want to display the icons associated with files . This is n't a problem for file types associated with normal desktop applications but only for those associated with ( metro/modern ) apps.If a file type is associated with an app and I am using AsParallel ( ) , I get only the default unknown file type icon ....
Ca n't get file icon for files associated with Windows apps when using AsParallel ( )
C_sharp : Suppose we have created Entities model , what is preferred way to work with it ? I 'm personally could n't make up my mind..Using ModelAdapter : looks neat ; but , context is created/released a lot sometimes , objects lose contact with context ; Using context in place : effectivebut , code becomes messyMixed ...
Working with entity framework , preferred way ?
C_sharp : If I have a class SubOfParent which is a sub-class of Parent , and two methods : why does the first doStuff get called when I pass a SubOfParent type object ? Thanks for any insight on this ! <code> public static void doStuff ( Parent in ) { } public static void doStuff ( SubOfPArent in ) { }
basic question on method overloading
C_sharp : I want to test GetParameters ( ) to assert the returned value includes `` test= '' within the value . Unfortunately the method responsible for this is private . Is there a way I can provide test coverage for this ? The problem I have is highlighted below : The problem is that info.TagGroups equals null in my ...
unit testing c # and issue with testing a private method
C_sharp : I wanted to make an array awaitable by implementing an extension methodbut even though IntelliSense says `` ( awaitable ) mytype [ ] '' , the compiler gives me an error when usingCalling await on a single object of mytype works fine . Why is that ? Am I doing something wrong ? Thanks for your help . <code> pu...
await array ; by implementing extension method for array
C_sharp : I 'm looking for the fastest way to find all strings in a collection starting from a set of characters . I can use sorted collection for this , however I ca n't find convenient way to do this in .net . Basically I need to find low and high indexes in a collection that meet the criteria.BinarySearch on List < ...
Fastest way to select all strings from list starting from
C_sharp : I 've got a ResourceDictionary in a xaml file that represents a skin in a folder on my hard drive in some random folder . Say D : \Temp2\BlackSkin.xaml.I 've set the permissions correctly to give full access so that 's not the issue.This ResourceDictionary BlackSkin.xaml references a BaseSkin.xaml like so : S...
How can I chain Resource Dictionaries that are externally loaded from disk , not included in project or assembly ?
C_sharp : ( This used to be a 2-part question , but since the second part is literally the important one , I decided to split this into two separate posts . See Using Serialization to copy entities between two ObjectContexts in Entity Framework for the second part.I want to create a fairly generic `` cloner '' of datab...
`` Cloning '' EntityConnections and ObjectContexts in Entity Framework
C_sharp : Silly question , but why does the following line compile ? As you can see , I have n't entered in the second element and left a comma there . Still compiles even though you would expect it not to . <code> int [ ] i = new int [ ] { 1 , } ;
Why is this c # snippet legal ?
C_sharp : In the following code , I would have expected calling a.Generate ( v ) would have resulted in calling V.Visit ( A a ) , since when Generate is called this is of type A. Hoewever , it appears that this is seen as being an Inter instead . Is it possible to have the intended behaviour without explicitly implemen...
How does polymorphism work with undefined intermediate types in C # ?
C_sharp : I 've tried looking for an answer but could n't find it . The 'issue ' is simple : If I have a collection of items using linq as follows : And another collection of items using linq but without a ToList ( ) : If now I try to iterate each item with a foreach ( I did n't try while or other kind of iteration met...
Database is locked when inside a foreach with linq without ToList ( )
C_sharp : In a current benchmark about mongodb drivers , we have noticed a huge difference in performance between python and .Net ( core or framework ) .And the a part of the difference can be explained by this in my opinion.We obtained the following results : We took a look to the memory allocation in C # and we notic...
How to reach the same performance with the C # mongo driver than PyMongo in python ?
C_sharp : As I understand , generics is an elegant solution to resolve issues with extra boxing/unboxing procedures which occur within generic collections like List . But I can not understand how generics can fix problems with using interfaces within a generic function . In other words , if I want to pass a value insta...
Generics and usage of interfaces without boxing of value instances
C_sharp : I 'm developing a wp7 game where the player draws lines in the program and a ball bounces off of them . I 'm using XNA and farseer physics . What is the best method for a user to draw a line , and then for the program to take it and turn it in to a physics object , or at least a list of vector2s ? I 've tried...
What is the best method in XNA to have the player paint smoothly on the screen ?
C_sharp : I have a factory class and CreateInstance methodThe factory can instantiate two differents subtypes depending on the value of tipoParametroEntita.TipoCampo.IdTipoCampo The point is the second argument of CreateInstance ( parametroEntitaMultiValoreDataSourceProvider ) is used only for creating instance of Tipo...
Factory CreateInstance argument method not necessary for a specific subtype
C_sharp : I 'm trying to write a method for coverting a given object to an instance of a given type . I started with this : Going in , I know that is n't going to work , but it illustrates the concept . Now , I 'm going to start having problems when I have types that wo n't cast automatically , like string -- > DateTim...
C # Help me with some Generic casting awesomeness
C_sharp : After seeing how double.Nan == double.NaN is always false in C # , I became curious how the equality was implemented under the hood . So I used Resharper to decompile the Double struct , and here is what I found : This seems to indicate the the struct Double declares a constant that is defined in terms of thi...
When is a System.Double not a double ?
C_sharp : I was going through some old code that was written in years past by another developer at my organization . Whilst trying to improve this code , I discovered that the query it uses had a very bad problem . The problem is that the column a.RRRAREQ_TRST_DESC does not exist . A fact you learn very quickly when ru...
The riddle of the working broken query
C_sharp : What 's the best way to fix the below synchronization issue by enhancing OrderManager ? OrderForm needs to get the latest list of orders and trades and subscribe to those events while OrderManager generates order and trade by another thread.Should I remove event pattern and implement like this ? Any other bet...
Synchronization issue in multiple event subscriptions and getting latest snapshot
C_sharp : I had C/C++ background . I came across a strange way of exchanging two values in C # . In C # , the above two lines do swap values between n1 and n2 . This is a surprise to me as in C/C++ , the result should be n1=n2=20 . So , how does C # evaluate an expression ? It looks like the + above is treated as a fun...
How does C # evaluate expressions which contain assignments ?
C_sharp : I 'm writing a generic code that should handle situations when data is loaded from multiple sources . I have a method with following signature : But it 's an overkill : when I pass TResult , I already know what TContract and TSection exactly are . In my example : But I have to write following : You can see th...
Simplify generic type inferring
C_sharp : I am trying to find an alternative to the following so that I can take advantage of the is operator.Something similar to the following , which does not compile . <code> public bool IsOfType ( Type type ) { return this._item.GetType ( ) == type ; } public bool IsOfType ( Type type ) { return this._item is type...
Is there a way to pass an argument to the is operator ?
C_sharp : Watching Advanced Memory Management by Mark Probst and Rodrigo Kumpera , I learned new techniques such as profiling Mono GC and using WeakReference.Yet I still do n't understand how to “ fix ” the Puzzle 2 from 28th minute : The controller holds a ref to button that holds a ref to event handler that holds a r...
How do I fix the GC cycle caused by a lambda event handler ?
C_sharp : We use the .NET 2.0 framework with C # 3.0 ( I think it 's the last version of C # which can run on the 2.0 version of the framework , correct me if I am wrong ) .Is there something built into C # which can make this type of parameter validation more convenient ? That sort of parameter validation becomes a co...
Nicer way of parameter checking ?
C_sharp : Let 's say I have a generic list of Fruit ( List < Fruit > fruits = new List < Fruit > ( ) ) . I then add a couple of objects ( all derived from Fruit ) - Banana , Apple , Orange but with different properties on the derived objects ( such as Banana.IsYellow ) .Then I can do this : But at execution time of cou...
How do I get a particular derived object in a List < T > ?
C_sharp : Possible Duplicate : C # Captured Variable In Loop I 'm working on a few simple applications of threading , but I ca n't seem to get this to work : The goal basically is to add threads to a queue one by one , and then to go through the queue one by one and pop off a thread and execute it . Because I have `` x...
Simple Threading in C #
C_sharp : I 'm pretty sure this is related to implementing interfaces and inheritance.In c # how does the System.Type class have the property Name ? When I example the code of the Type class from metadata or using the Object Browser I see the Type class does n't have : defined anywhere . I also see that Type inherits f...
How does c # System.Type Type have a name property
C_sharp : Why does expr1 compile but not expr2 ? <code> Func < object > func = ( ) = > new object ( ) ; Expression < Func < object > > expr1 = ( ) = > new object ( ) ; Expression < Func < object > > expr2 = func ; // Can not implicitly convert type 'System.Func < object > ' to 'System.Linq.Expressions.Expression < Syst...
Why does an Expression type in .NET allows construction from a function but not conversion from one ?
C_sharp : I 've noticed some bizarre behavior in my code when accidentally commenting out a line in a function during code review . It was very hard to reproduce but I 'll depict a similar example here.I 've got this test class : there is No assignment to Email in the GetOut which normally would throw an error : The ou...
out parameters of struct type not required to be assigned
C_sharp : Consider this code : in above code we do n't use method hiding.when create instance of student and call showinfo method my output is I am Student i do n't use new keyword.Why does not call parent method when we do n't use method hiding ? <code> internal class Program { private static void Main ( string [ ] ar...
Why does not call parent method when we do n't use method hiding ?
C_sharp : I am using the default Sitemap provider with secutiry trimming . But , some how , I get : A network-related or instance-specific error occurred while establishing a connection to SQL Server . I 'm thinking the sitemap provider is looking for the roles in the wrong place . My configuration is like this : The S...
Sitemap Security Trimming throws SQL error
C_sharp : When overriding the Equals ( ) method , the MSDN recommends this : But if we know that the subclass directly inherits from Object , then is the following equivalent ? Note the ! base.Equals ( ) call : <code> class Point : Object { protected int x , y ; public Point ( int X , int Y ) { this.x = X ; this.y = Y ...
Overriding Equals ( ) : is null comparison redundant when calling base.Equals ( ) ?
C_sharp : I have a list of invoices that and I transferred them to an Excel spreadsheet . All the columns are created into the spreadsheet except for the Job Date column . That is blank in the spreadsheet . Here 's the code : The sql returns all the correct information and as you can see the job date is there : But whe...
Column missing from excel spreedshet
C_sharp : Let 's say there is a class A with an parameterless instance methodIt 's easy to invoke the method using reflection : However , I want to invoke the method as if it is staticIs there any way I can get this staticmethod ? NOTE : I want Something to be universal , i.e . A can be any class , and foo can be any i...
Invoke instance method statically
C_sharp : I saw some code written by another developer that looks something like this : ( It is ALL over the place in the code ) Question 1 : Would that error logging code even get called ? If there was no memory , would n't an System.OutOfMemoryException be thrown on that first line ? Question 2 : Can a call to a cons...
Would simple class instantiation ever fail in C # ?
C_sharp : I have system being developed for an HR system . There are Accountant employees and Programmer employees . For the first month of joining the company , the employee is not given any role . One employee can be an Accountant and a programmer at the same time . I have a design shown by the following code.Now , I...
Issue in using Composition for “ is – a “ relationship
C_sharp : I wrote a Thread helper class that can be used to execute a piece of code in Unity 's main Thread . This is the functions blue print : The complete script is really long and will make this post unnecessarily long . You can see the rest of the script helper class here.Then I can use unity 's API from another T...
Delegate Closure with no memory allocation
C_sharp : I want to create a .Net Core console app that gets run by the Windows Task Scheduler . In this console app I want to find the path of the directory where the app 's .exe file is located.I publish the app to create the .exe file by running this line of code in a command prompt : dotnet publish -r win-x64 -c Re...
How to get the path of the directory where the .exe file for a .Net Core console application is located ?
C_sharp : So in C # , you might have the following code : As soon as you enter DoSomething , the CLR sets up space for int x . Why does it not wait until it reaches the line with int x =5 on it ? Especially since even though x is bound , it does n't let you actually use it until that line is reached anyway ? <code> voi...
Why does C # bind the local variables up-front ?
C_sharp : If you have a brush and pen as in : and dispose them like so : How would you dispose it if it was : Pen p = CreatePenFromColor ( color ) which would create the brush and pen for you ? I ca n't dispose the brush inside this method , right ? Is this a method not to be used with disposable objects ? EDIT : What ...
How to handle disposable objects we do n't have a reference to ?
C_sharp : BackgroundI have an application where 3 views utilize html5 offline app functionality . As such , I have an app manifest generated in a razor view . A cut-down version of this view may look like the following : In order for the offline app to function correctly , the cached files must exactly match those requ...
Service/extension for getting a cache-busting 'version string '
C_sharp : I have the following extension method to find an element within a sequence , and then return two IEnumerable < T > s : one containing all the elements before that element , and one containing the element and everything that follows . I would prefer if the method were lazy , but I have n't figured out a way to...
Lazily partition sequence with LINQ
C_sharp : Here is the equality comparer I just wrote because I wanted a distinct set of items from a list containing entities.Why does Distinct require a comparer as opposed to a Func < T , T , bool > ? Are ( A ) and ( B ) anything other than optimizations , and are there scenarios when they would not act the expected ...
Questions about IEqualityComparer < T > / List < T > .Distinct ( )
C_sharp : When implementing IEnumerable & IEnumerator on a class I was writing during training , I noticed that I was required to specify two implementations for the property `` Current '' .I roughly understand that I 'm implementing some non-generic version of IEnumerator and a `` Current '' property for it , however ...
Why must I define IEnumerator < T > .Current & IEnumerator.Current , and what does that achieve ?
C_sharp : Sorry for the long question but I 'm kinda new to C # ( I used to use VB.Net ) I fully understand the difference between Overriding and Overloading in both VB.Net and C # .. so there 's no problem with the overriding.Now , in VB.Net there 's a difference between Shadowing ( using the keyword Shadows ) and Ove...
C # vs VB.Net , what 's the difference between Shadowing and [ Overloading ( without changing the arguments ) ]
C_sharp : I using Unity 2019.2.14f1 to create a simple 3D game.In that game , I want to play a sound anytime my Player collides with a gameObject with a specific tag.The MainCamera has an Audio Listener and I am using Cinemachine Free Look , that is following my avatar , inside the ThridPersonController ( I am using th...
Unity3D playing sound when Player collides with an object with a specific tag
C_sharp : It is my understanding that C # is a safe language and does n't allow one to access unallocated memory , other than through the unsafe keyword . However , its memory model allows reordering when there is unsynchronized access between threads . This leads to race hazards where references to new instances appea...
Can memory reordering cause C # to access unallocated memory ?
C_sharp : I am trying to use the SMO for Sql Server 2008 R2 Standard , but I am running into an issue whenever I try to Dump an object.The relevant code : Edit : A work around that I found is to use the Dump method with a fixed recursion depth e.g . Dump ( 1 ) , but the exception is at a different level for each object...
Using LinqPad with SMO
C_sharp : Something I do often if I 'm storing a bunch of string values and I want to be able to find them in O ( 1 ) time later is : This way , I can comfortably perform constant-time lookups on these string values later on , such as : However , I feel like I 'm cheating by making the value String.Empty . Is there a m...
'Proper ' collection to use to obtain items in O ( 1 ) time in C # .NET ?
C_sharp : I would like to enumerate the strings that are in the string intern pool.That is to say , I want to get the list of all the instances s of string such that : Does anyone know if it 's possible ? <code> string.IsInterned ( s ) ! = null
Read the content of the string intern pool
C_sharp : I have encryption method that runs incredible slowly . It takes around 20 minutes to encrypt several hundred MB of data . I 'm not sure if I 'm taking the right approach . Any help , thoughts , advice would be greatly appreciated.Thanks for your help ! <code> private void AES_Encrypt ( string inputFile , stri...
How to Speed Up this Encryption Method C # Filestream
C_sharp : I have the following code : This code results in a compiler error : can not implicity convert type 'int ' to 'short'If I write the condition in the expanded format there is no compiler error : Why do I get a compiler error ? <code> Int16 myShortInt ; myShortInt = Condition ? 1 :2 ; if ( Condition ) { myShortI...
cast short to int in if block
C_sharp : I made an extension method to find the number of consecutive values in a collection . Because it is generic , I allow the caller to define the `` incrementor '' which is a Func < > that is supposed to increment the value in order to check for the existence of a `` next '' value.However , if the caller passes ...
How do I avoid infinite recursion with a custom enumerator ?
C_sharp : I have a list of properties and their values and they are formatted in a Dictionary < string , object > like this : There are two classes . Person is composed of the string Name and primitive Age as well as the complex Address class which has House , Street , City , and State string properties.Basically what ...
How can you translate a flat dotted list of properties to a constructed object ?
C_sharp : a ) Do s and s1 reference variables point to same string object ( I ’ m assuming this due to the fact that strings are immutable ) ? b ) I realize equality operators ( == , > etc ) have been redefined to compare the values of string objects , but is the same true when comparing two strings using static method...
Since strings are immutable , do variables with identical string values point to the same string object ?
C_sharp : I ca n't figure out the use for this code . Of what use is this pattern ? [ code repeated here for posterity ] <code> public class Turtle < T > where T : Turtle < T > { }
What use is this code ?
C_sharp : I 'm designing a linguistic analyzer for French text . I have a dictionary in XML format , that looks like this : Sorry it 's so long , but it 's necessary to show exactly how the data is modeled ( tree-node structure ) .Currently I am using structs to model the conjugation tables , nested structs to be more ...
How to Represent Conjugation Tables in C #
C_sharp : I was wondering , An Instance of class is on the Heap . ( value types inside it are also in the heap ) .But what about the opposite case ? There is one question here but it did n't mention any GC related info.So - How does GC handle this situation ? <code> public struct Point { object o ; public int x , y ; p...
Struct with reference types and GC ?
C_sharp : I am trying to solve this business issue : A user gets 10 attempts to login every 5 minutesIf a user exceeds 10 attempts , I display a `` You need to wait tologin '' messageOnce 5 minutes have elapsed , I need to reset the number of attemptsand let the user attempt 10 more times.I 'd like to do this without u...
How to solve this Timeslot issue in C #
C_sharp : For all DI examples I have seen , I always see the dependencies as other classes , like services . But an object may depend , heavily and/or crucially in fact , on configuration values such as Strings and resource wrappers ( File/Path/URI/URL , as opposed to an entire big value string/document , or a reader )...
Are value objects valid dependencies for DI design pattern ?
C_sharp : I keep running into a pattern whereby I want to select rows from an Entity Collection ( EF4 ) and use the data to create new rows in a different entity collection.The only way I have found to do this is to perform the following steps : If I try to create a new OtherEntity in the select then I get an EF except...
Is it necessary to always Select ( ) ... new { Anon } ... AsEnumerable ... Select ( new EntityType { } ) every time ?