text
stringlengths
46
37.3k
title
stringlengths
12
162
C_sharp : I have run some tests on the new spatial library SqlGeography in SQL Server 2016 , which according to Microsoft should be a lot faster than the previous versions : SQL Server 2016 – It Just Runs Faster : Native Spatial Implementation ( s ) . Apply SQL Server 2016 and a breadth of methods and spatial activitie...
SqlGeography spatial operations slow - SQL Server 2016
C_sharp : Exhibit 1 : some code wrapping an Async ( not async ! ) network call into a TaskInstalling .Net 4.5 ( not pointing VS at it , nor recompiling ) stops this working . The callback is never invoked.Any ideas what could be causing this , and otherwise , what I can do to try and further narrow down the root cause ...
.Net 4.5 killed my TPL , now what ?
C_sharp : I try to get a data record ID from Entity Framework : The problem is , that there is a PlantArea with the ID 0 . SingleOrDefault returns 0 , though , if it does n't find any record . So how can I differenciate between ID 0 and the case , where no data was found ? My first idea was to provide a default value -...
Define default value for SingleOrDefault Linq method
C_sharp : Assume I have an array of bytes which are truly random ( e.g . captured from an entropy source ) . Now , I want to get a random double precision floating point value , but between the values of 0 and positive 1 ( like the Random.NextDouble ( ) function performs ) .Simply passing an array of 8 random bytes int...
Get random double ( floating point ) value from random byte array between 0 and 1 in C # ?
C_sharp : I have a KeyPressed signal in Gtk # /mono C # for two different purposes which are not present in the default TreeView : a ) go to the next cell by pressing TAB , and b ) start editing by pressing any key.The TreeView is simple , it has a ListStore showing only rows and columns , i.e . it holds tabular data.T...
How to manage key pressings for special purposes in Gtk # TreeView ?
C_sharp : I have a WPF application that does a lot of matching across large datasets , and currently it uses C # and LINQ to match POCOs and display in a grid . As the number of datasets included has increased , and the volume of data has increased , I 've been asked to look at performance issues . One of the assumptio...
Differences Between Output of C # Compiler and C++/CLI Compiler
C_sharp : Say I have the following class definitions : If I would want to do the work done in DoWork ( ) , on the form , asynchronously I could add a method ( GetCalculationTask ) that returns a task using Task.Run ( ) and add a async eventhandler i.e . For a button ( MethodOne ) . Please correct me if I 'm wrong , but...
Best practice on using async / await
C_sharp : I have following code in c # In this case I am getting 0 and 3 but in the following case I am getting 3,3 why is it so ? <code> class Test { public static int X = Y ; public static int Y = 3 ; } static void Main ( ) { Console.WriteLine ( Test.X ) ; Console.WriteLine ( Test.Y ) ; } class Test { public static i...
Static field initializers in c #
C_sharp : I 'm trying to trim a string with String.Trim : But I 'm getting the result of : Instead of : I also tried using : But it still returns the same result.Also if I do : I get : I 'm really confused why this is happening . Could it be because the semicolon is not the last character in the string ? Here is the fu...
Why is String.Trim not trimming a semicolon ?
C_sharp : With the new C # 8 Using Declaration Syntax , what is containing scope of a second consecutive using statement ? TL ; DRPrevious to C # 8 , having a consecutive using statement like : would expand to something like the following ( My Source ) : I know that there are two other possible expansions but they all ...
C # 8 Using Declaration Scope Confusion
C_sharp : Short and simple . Does the new string interpolation in C # 6.0 rely on reflection ? I.e . doesuse reflection at runtime to find the variable `` name '' and its value ? <code> string myStr = $ '' Hi { name } , how are you ? `` ;
Does C # 6.0 's String interpolation rely on Reflection ?
C_sharp : When I use Entity Framework against a SQL table , it only refers to the necessary columns in the generated SQL : becomesHowever , if I make an analogous query against a SQL view , Entity Framework generates SQL referring to every column in the view : becomesI 'm sure SQL Server will perform its own optimizati...
Entity Framework selects too many columns in views
C_sharp : Quick Question , See this code : And : Why result.Add ( value ) not executed ? However this not executed , Another question that is have a way do a foreach on a IEnumerable with Extention Method ? Except this way : IEnumerable.ToList ( ) .Foreach ( p= > ... ) <code> List < int > result = new List < int > ( ) ...
Foreach with Extension Method on IEnumerable
C_sharp : This works perfectly.. This returns a compiler error ... Same happen when using reflection ... So , does somebody know why the enum-base is just an integral-type ? <code> public enum NodeType : byte { Search , Analysis , Output , Input , Audio , Movement } public enum NodeType : Byte { Search , Analysis , Out...
Why can you use just the alias to declare a enum and not the .NET type ?
C_sharp : I came across this line of code in a book : This sort of thing seems like tail-chasing to me ... Why is the c = > c. necessary ? Would n't the following be understandable ( by the compiler , and even more so by humans ) ? I 'm sure there 's all kinds of fancy stuff going on behind the scenes that purportedly ...
Why do lambdas require = > as part of their syntax ?
C_sharp : Recently I moved from VB to C # , so I often use a C # to VB.NET converter to understand syntax differences.While moving next method to VB I noticed an interesting thing.C # original code : VB.NET result : C # 's ++ operator replaced with System.Threading.Interlocked.IncrementDoes it mean that not threadsafe ...
Does C # ++ operator become threadsafe in foreach loop ?
C_sharp : I know how to use locks in my app , but there still few things that I do n't quite understand about locking ( BTW - I know that the lock statement is just a shorthand notation for working with Monitor class type ) .From http : //msdn.microsoft.com/en-us/library/ms173179.aspx : The argument provided to the loc...
Few confusing things about locks
C_sharp : I find myself quite often in the following situation : I have a user control which is bound to some data . Whenever the control is updated , the underlying data is updated . Whenever the underlying data is updated , the control is updated . So it 's quite easy to get stuck in a never ending loop of updates ( ...
Event circularity
C_sharp : I need an idea how to do the following animation idea . Lets assume I have a view model defined as such : The IPage object is , plainly spoken , a piece of paper with the title and the description written on it . When the IPage object changes in my view model I want to have an animation as outlined below : Th...
WPF animation idea for flipping a page
C_sharp : I was tasked with converting a solution from VB to C # . There were 22 projects and hundreds of classes , so I decided to research converters . I finally settled on SharpDevelop , which is an IDE with an included converter . I ran it on each of my projects , and have plenty of errors to fix , but I should be ...
Converting from VB to C #
C_sharp : I have list object 's . But it has duplicate records for 2 key - itemId and itemTypeId . How do I remove duplicates from the list ? I tried GroupBy - but it can only use one key at a time.Actual Result : to1 and to3 <code> public class TestObject { public string Name ; public int itemTypeId ; public int itemI...
How to remove duplicate object in List with double key
C_sharp : I have two methods ( in C # ) : These operations have no common objects ( aside from the pizzas that are passed from one to the other ) , and are thread-safe . They each take several seconds to execute and they each use different resources ( oven vs car ) . As such , I want to run them at the same time.How do...
Pizza , Threading , Waiting , Notifying . What does it mean ?
C_sharp : I was writing some unit tests for a utility library when I came across a test I would expect to fail that actually passed . The issue is related to comparing two float variables , versus comparing one float ? and one float variable.I 'm using the latest versions of both NUnit ( 2.6.0.12051 ) and FluentAsserti...
Is this a bug when comparing a nullable type with its underlying type using FluentAssertions ?
C_sharp : I have a list of prime numbers up to 2 000 000 . That 's a list containing almost 150 000 very large integers . I want a sum of all the numbers in it . Here 's a random list of large integers just for demonstration : I 'm getting a `` Arithmetic operation resulted in an overflow '' exception . I guess the sum...
List sum too large , throwing overflow exception
C_sharp : I 'm using an ActiveDirectory server to query the groups that a user belongs to . I would like to get all the groups that a user belongs to , but using the Network Management funcions of the Network API.I realized that already exist a function called NetUserGetGroups , but unfortunately , this function does n...
How to get user 's groups using the Network API
C_sharp : I 'm creating a chain of responsibility pipeline using System.Func < T , T > where each function in the pipeline holds a reference to the next.When building the pipeline , I 'm unable to pass the inner function by reference as it throws a StackOverflowException due to the reassignment of the pipeline function...
Chain of responsibility using Func
C_sharp : Hi lets say i have tree of following typelets say root of the tree is I know it is possible to check length of this tree using recursionbut is this possible to check length of this tree using linq ? <code> public class Element { public List < Element > element ; } Element root = GetTree ( ) ;
Checking length of tree using linq
C_sharp : I 'm trying to create a binding from code in a library that targets multiple frameworks ( WPF , WinRT , UWP etc ) , and I 'm hitting a brick wall . The property I 'm trying to bind to is a custom attached property . In WPF , I can pass the DependencyProperty itself as the binding path : But in WinRT the Prope...
Binding from code to a custom attached property in WinRT/UWP
C_sharp : I am new to MVC and started with MVC 4 . I want to make an online shop application.-Same shopping logic will be used by two different web sites/domains.-And the views must alter according to domain name and their mobile versions.Logic file structe is like this : View file structure for first domain : View fil...
MVC 4 same logic with different view folders
C_sharp : We are using System.Linq.Expressions.Expression to build custom expressions which are applied on the .Where ( ) of our IQueryable.What I want to achieve is , to apply the .HasFlag ( ) method ( introduced in EF 6.1 ) on the property which is then used in the .Where ( ) expression.I have following code : The va...
LINQ to Entities does not recognize the method 'Boolean HasFlag ( System.Enum ) ' when creating the expression via System.Linq.Expressions.Expression
C_sharp : According to MSDN , Environment.StackTrace can throw ArgumentOutOfRangeException but I do n't understand how this is possible.Environment.cs StackTrace ( source ) Calls GetStackTrace ( Exception , bool ) where Exception is null.Environment.cs GetStackTrace ( Exception , bool ) ( source ) ( comments removed , ...
How can Environment.StackTrace throw ArgumentOutOfRangeException ?
C_sharp : I 'm implementing some real-time charts in a C # WPF application , but am using WinForms charts as they are generally easy to work with and are surprisingly performant.Anyway , I 've got the charts working just fine except for one major issue which I ca n't for the life of me figure out : When I add data to t...
How to cure C # winforms chart of the wiggles ?
C_sharp : It is possible to register dependencies manually : When there are too much dependencies , it becomes difficult to register all dependencies manually.What is the best way to implement a convention based binding in MVC 6 ( beta 7 ) ? P.S . In previous projects I used Ninject with ninject.extensions.conventions ...
Convention based binding in ASP.NET 5 / MVC 6
C_sharp : WCF makes it easy to call services synchronously or asynchronously , regardless of how the service is implemented . To accommodate clients using ChannelFactory , services can even define separate sync/async contract interfaces . For example : This allows the client to reference either contract version , and W...
Unit-test WCF contracts match for sync / async ?
C_sharp : I have been handing the closing and aborting of channels this way : Assume only a single thread uses the channel . How do we know the channel will not fault right after checking the state ? If such a thing were to happen , the code would try to Close ( ) and Close ( ) will throw an exception in the finally bl...
Is it possible for a WCF channel to fault right after checking the state ( single thread ) ?
C_sharp : How would you create a Class that whichever class extends the Class , methods are automatically invoked/called . Just edit my question if it sounds misleading . I 'll just showcase some samplesExample 1 : In unity when you extend monobehavior your methods are automatically called . I do n't know if I 'm right...
Calling methods from a super class when a subclass is instantiated
C_sharp : I have the following code which is in a transaction . I 'm not sure where/when I should be commiting my unit of work.On purpose , I 've not mentioned what type of Respoistory i 'm using - eg . Linq-To-Sql , Entity Framework 4 , NHibernate , etc.If someone knows where , can they please explain WHY they have sa...
At which line in the following code should I commit my unit of work ?
C_sharp : Given the following method : This works if I call it passing a array of strings : But will not work if I call it using string arguments : I understand that the compiler will wrap Michael and Jordan on an array , so should n't the results be the same on both cases ? <code> static void ChangeArray ( params stri...
C # Inconsistent results using params keyword
C_sharp : I was just looking at the question `` SubQuery using Lambda Expression '' and wondered about compiler optimization of Linq predicates.Suppose I had a List < string > called names , and I was looking for the items with the shortest string length . So we have the query names.Where ( x = > x.Length == names.Min ...
In a Linq predicate , will the compiler optimize a `` scalar '' call to Enumerable.Min ( ) or will it be called for each item ?
C_sharp : I have two questions : Question 1 Background : I noticed when looking at the implementation of 'AsEnumerable ( ) ' method in LINQ from Microsoft , which was : Question 1 : I was expecting some kind of casting or something here , but it simply returns the value it was passed . How does this work ? Question 2/3...
Internal Implementation of AsEnumerable ( ) in LINQ
C_sharp : I have a problem with writing a C # linq query for retrieving data from the database , based on multiple columns of a filter list.The list of items contains multiple columns ( For example A and B ) and is dynamic.My first idea was to write an any statement in an where statement , but this is not allowed in EF...
Retrieve records from the database matching multiple values of a list
C_sharp : I am drawing a header for a timeline control.It looks like this : I go to 0.01 millisecond per line , so for a 10 minute timeline I am looking at drawing 60000 lines + 6000 labels.This takes a while , ~10 seconds.I would like to offload this from the UI thread.My code is currently : I had looked into Backgrou...
10000's+ UI elements , bind or draw ?
C_sharp : In unity3D I am creating and destroying capsule dynamically at run-time . I used space to create capsule and C for destroying.I want create multiple object and destroy multiple object at time . When I pressed Space multiple times object is creating multiple time it fine . But the problem is when I pressed C m...
How to Destroy multiple gameObject at runtime ?
C_sharp : This is a question I was asked at my interview recently : Which 'Random ' object ( s ) would get collected during the 'GC.Collect ( ) ' call ? I answered that this is an implementation-specific question and it highly depends on the GC implementation and the corresponding weak reference semantics . As far as I...
Which of these objects are eligible for garbage collection ?
C_sharp : Lets say I have a function that needs to return some integer value . but it can also fail , and I need to know when it does.Which is the better way ? orthis is probably more of a style question , but I 'm still curious which option people would take.Edit : clarification , this code talks to a black box ( lets...
which is better , using a nullable or a boolean return+out parameter
C_sharp : I have an application that needs to take in several million char* 's as an input parameter ( typically strings less than 512 characters ( in unicode ) ) , and convert and store them as .net strings.It turning out to be a real bottleneck in the performance of my application . I 'm wondering if there 's some de...
Optimizing several million char* to string conversions
C_sharp : I 'm having trouble serialising and de-serialising NodaTime 's LocalTime through a WebAPI.Class definitionTry to serialize the outputI want to time format formatted to a ISO like standard e.g . 12:34:53 , but instead it de-serialisers to the following with local time represented as ticks ; { `` ExampleLocalTi...
Proper serialization of LocalTime through WebAPI
C_sharp : Somebody gives me a type t.I 'd like to know if that type is an enumeration or not . <code> public bool IsEnumeration ( Type t ) { // Mystery Code . throw new NotImplementedException ( ) ; } public void IsEnumerationChecker ( ) { Assert.IsTrue ( IsEnumeration ( typeof ( Color ) ) ) ; Assert.IsFalse ( IsEnumer...
Is there any way to check that a type is a type of enumeration ?
C_sharp : I am getting all events , with a certain attribute , and I want to modify these events adding a call to another method.What I want is basically what is commented above . `` Modify '' the subscribed methods of the event . I guess I ca n't subscribe to it , because I need to pass the parameters the method is pa...
How can I change a method assigned on an event ?
C_sharp : I would like to parse an input string that contains either a time , a date and time , or just a date , and I need to know which parts where included in the input string.Parsing the actual values is not a problem : These all successfully parse as you 'd expect.However , if the date element is not provided , Da...
Parsing Time , Date/Time , or Date
C_sharp : EDIT 1 : I know there are alternatives such as telescoping , this was a purely educational question.I know that this is true , but why must it be ? It seems like with something like this : The compiler could change the method to something like this : Why would n't that work , or would it , and it 's just a de...
Why must default method parameters be compile-time constants in C #
C_sharp : I 'm trying to create several enums as such , that gives the syntax of Dropdown.Category.Subcategory . However , I have been reading that this is n't such a good idea . My choice for this was mostly because I could n't think of any other way to select different enum values depending on the choice of the categ...
Alternative to nesting enums
C_sharp : If I have two yield return methods with the same signature , the compiler does not seem to be recognizing them to be similar.I have two yield return methods like this : With this , I would expect the following statement to compile fine : Func < int , IEnumerable < int > > generator = 1 == 0 ? EvenNumbers : Od...
C # compiler not recognizing yield return methods as similar ?
C_sharp : I 'm trying to create a set of C # classes that I can schedule to run at a future time . The intention is to programmatically schedule these via other parts of my code.This is the current class I 'm trying to call via COM.Here 's how I 'm attempting to schedule the taskMicrosoft.Win32.TaskScheduler is version...
Unable to register a COM object for usage in a scheduled task
C_sharp : PreambleI have been investigating a concept and what I am posting below is a cut down version of what I have been trying . If you look at it and think `` That does n't make any sense to do it that way '' then it is probably because I does n't make any sense - there may be more efficient ways of doing this . I...
SQL ORDER BY within OVER clause incompatible with CLR aggregation ?
C_sharp : Consider the following codeSteps to reproducePut a breakpoint on Console.Read ( ) ; Run to breakpointInspect count++ ( should display 0 ) Inspect values2 and populate the Results ViewInspect count++ ( should display 100 ) ProblemGiven that I have only taken 50 items from values1 , I would expect count++ to di...
LINQ projection ( Select ) returning an odd result
C_sharp : I 've read that it is usually bad practice to extend System.Object , which I do agree with.I am curious , however , if the following would be considered a useful extension method , or is it still bad practice ? It is similar to extending System.Object but not exactly , This essentially allows any object to in...
Extension method that extends T - bad practice ?
C_sharp : When I bump my mousewheel , my WPF application crashes sometimes , with an OverflowException . Here 's the start of the stack trace : From that , I 've traced it down to the WindowChrome - I can even reproduce it with just the WindowChrome . But it seems like it has to be fullscreen . What 's going on here ? ...
Why does my WPF application crash when I bump my mousewheel ?
C_sharp : I 'm having trouble understanding why arrays in C # are covariant and what benefits this covariance can bring . Consider the following trivial code example : This code will compile okay , but will unceremoniously and perhaps unsurprisingly explode at runtime.If I try to attempt this same thing using generics ...
Why are C # arrays covariant and what benefits does it bring ?
C_sharp : If I have a synchronous method `` GetStrings ( ) '' : ( which itself calls async method `` GetString ( ) '' ) And I call this synchronous `` GetStrings ( ) '' method from an async method : What would be the behavioural difference , if GetStrings ( ) was actually async ? ( and performed an await on the Task.Wh...
What happens when you await a synchronous method
C_sharp : Hi i have two Writablebitmap , one from jpg and another from png and use this method to mix color in a loop : My problem is in alpha channel , my watermark effect result is bad ( quality ) ! This is the original png.This is the original jpg.Any Help ? <code> private static Color Mix ( Color from , Color to , ...
Png over jpeg ( water mark effect ) bad quality ?
C_sharp : In C # I have ( saw with Visual Studio watch tool ) : And in C++ : Why are the values not the same ? And how can I get -3.40282347E+38 ( C # value ) in C++ ? <code> float.MinValue = -3.40282347E+38 std : :numeric_limits < float > : :min ( ) = 1.17549435e-038
Why is float.min different between C++ and C # ?
C_sharp : Given the following code , Resharper will correctly warn me about a possible NullReferenceException on foo.Bar because there could be null elements in the enumerable : One way to satisfy the static analyzer is to explicitly exclude nulls : I find myself typing .Where ( x = > x ! = null ) a lot , so I wrapped ...
How do I tell Resharper that my IEnumerable method removes nulls ?
C_sharp : I recently came across what seems to puzzle my logic of maths in a piece of codeFor some reason , C # is claiming that this is false but if one were to think logically , 0.123 is larger than 0.Is there any reason that it is claiming that 0.123 is smaller than 0 ? I have read that there will be a comparison is...
if ( ( 123 / 1000 ) > 0 ) returns false
C_sharp : There are two Point3D 's ( A and B ) and I want to calculate the points of a cuboid ( a , b , c ... h ) surrounding the line between A and B like a hull : There is one degree of freedom , the angle of the cuboid , because it can rotate around the line AB . I am not sure yet if this is a problem.I tried to cal...
Calculating the Point3Ds of a Cuboid around a Line
C_sharp : i use the httpclient from Microsoft.Net.Http ( version 2.2.22 ) to request some of my mvc pages.My page returns a HttpStatusCodeResult like : With the httpclient it is not problem to call the page . But i could n't find a way to access the statusDescription ( `` Blub Blub '' ) . Is there a way to access the d...
HttpClient StatusDescription is missing
C_sharp : I found this explanation and solution for using Dapper to search a VARCHAR field using a string as input : Source : Dapper and varcharsBut is there a way to adapt this to do the DbString conversion for every item in a list ( using an IN clause ) ? The query I am trying to run looks like this : Unfortunately ,...
How do I tell Dapper to use varchar for a list of params in a `` WHERE '' clause that uses `` IN '' ?
C_sharp : What are some good ways to handle known errors that occur in a method ? Let 's take a user registration method as an example . When a user is signing up , a method SignUp ( User user ) is called . There are a few known errors that might happen.Email is already registeredUsername is already registeredEtcYou co...
Handling Known Errors and Error Messages in a Method
C_sharp : I 've been having really bad memory problems with an ASP.NET Application . It seems as if every time the page loads , the old previous instance of the page is not removed from memory . If you press F5 ten times , the memory adds 10-20MB to the instance . During Stress and performance testing , this would max ...
ASP.NET Pages not removed from memory
C_sharp : I wan na select some records from the informix database via Odbc connection and insert them to a Sql database table.I 've searched regrading that , but they did n't solve my issue . Is it possible to have both connections at one place ? Any help or suggestions would be appreciated . Thanks <code> INSERT INTO ...
Odbc & Sql connection in one query
C_sharp : I wrote User Control ( yay ! ) . But I want it to behave as a container . But wait ! I know about Trick . The problem is - I do n't want all of my control to behave like container , but only one part . One - de facto - panel ; ) To give wider context : I wrote a control that has Grid , some common buttons , l...
UserControl with header and content - Allow dropping controls in content panel and Prevent dropping controls in header at design time
C_sharp : I was fiddling around with parsing in C # and found that for every string I tried , string.StartsWith ( `` \u2D2D '' ) will return true . Why is that ? It seems it works with every char . Tried this code with .Net 4.5 the Debugger did not break . <code> for ( char i = char.MinValue ; i < char.MaxValue ; i++ )...
Why does string.StartsWith ( `` \u2D2D '' ) always return true ?
C_sharp : I am currently working on a C # .NET Add-In for Microsoft Outlook.The goal of the Add-In is , to capture the search input from the Outlook Instant Search , and show in a Custom Pane my own search results.It works pretty well , and with subclassing the Outlook Window with a Native Window , I get the search str...
Native Window : Release Handle On Close
C_sharp : This compiles correctly in C # 7.3 ( Framework 4.8 ) : I know that this is syntactic sugar for the following , which also compiles correctly : So , it appears that ValueTuples can be assigned covariantly , which is awesome ! Unfortunately , I do n't understand why : I was under the impression that C # only su...
What makes ValueTuple covariant ?
C_sharp : I have encountered a problem while using Invariants with Code Contracts . I want to define an Invariant within my abstract class but it is simply ignored . The code below shows my interface and the abstract class.Afterwards , I implement this interface within my Point class and create an object from it . This...
Code Contracts : Invariants in abstract class
C_sharp : Would it be considered bad practice to have a viewmodel that has a property of another view model ? ... as in : EDITA little more about my particular situation : I have a view model that currently contains 2 domain classes . I pass this viewmodel to a view that loads 2 partials views ( one for each domain cla...
Is it bad practice to have a ViewModel with a property typed as another ViewModel in ASP.NET MVC
C_sharp : I have some code that was recently upgraded from EF 4.2 to EF 5.0 ( actually EF 4.4 since I am running on .Net 4.0 ) . I have discovered that I had to change the syntax of my query , and I 'm curious as to why . Let me start off with the problem.I have an EventLog table that is populated by the client periodi...
Why does EF 5.0 not support this EF 4.x LINQ syntax when compiling to sql ?
C_sharp : Let 's say , hypothetically ( read : I do n't think I actually need this , but I am curious as the idea popped into my head ) , one wanted an array of memory set aside locally on the stack , not on the heap . For instance , something like this : I 'm guessing the answer is no . All I 've been able to find is ...
Are stack based arrays possible in C # ?
C_sharp : Let 's assume I have a class that has a property of type Dictionary < string , string > , that may be null.This compiles but the call to TryGetValue ( ) could throw at a NullRef exception at runtime : So I 'm adding a null-propagating operator to guard against nulls , but this does n't compile : Is there an a...
Null propagation operator , out parameters and false compiler errors ?
C_sharp : My test code : My problem is : I can not directly declare pictureUrl like this : I 've tried to do that , it threw me error message : 'Task < UserProfileViewModels > ' does not contain a definition for 'PictureUrl ' and no extension method 'PictureUrl ' accepting a first argument of type 'Task < UserProfileVi...
Why can not I directly access property `` .SingleAsync ( ) .Property '' ?
C_sharp : I am creating ( then altering ) a bitmap using `` unsafe '' code in a C # winforms project . This is done every 30ms or so . The problem I 'm having is that `` noise '' or random pixels will show up sometimes in the resulting bitmap where I did not specifically change anything.For example , I create a bitmap ...
How to avoid `` noise '' when setting pixels of image in unsafe code
C_sharp : This is very baffling to me . Somehow the IndexOf ( string ) method of my List < string > object is returning -1 even though the value is CLEARLY in the List.string prefix is `` 01 '' validPrefixes index 0 is `` 01 '' .indexOf is -1 . Umm ... How ? <code> protected readonly List < string > validPrefixes = new...
List < string > object IndexOf returning -1 . How ?
C_sharp : I have a situation where I have a simple , immutable value type : When I box an instance of this value type , I would normally expect that whatever it is that I boxed would come out the same when I do an unbox . To my big suprise this is not the case . Using Reflection someone may easily modify my box 's memo...
Why does the CLR allow mutating boxed immutable value types ?
C_sharp : Given a set of sixteen letters and an English dictionary file , need to find a solution where those sixteen letters can fit into a 4x4 grid so that a valid word can be read across each row , and down each column.My current solution:1 ) Get a list of all of the possible 4-letter words that can be made with tho...
My iteration is taking forever . Looking for a better way
C_sharp : I wrote the following console app to test static properties : As this console app demonstrates , the MyProperty property exists once for all instances of BaseClass . Is there a pattern to use which would allow me to define a static property which will have allocated storage for each sub-class type ? Given the...
What is the best way to define a static property which is defined once per sub-class ?
C_sharp : I am using application insights sdk for a wpf app I 've been working on to capture some simple telemetry . I am loading the configuration file that looks like thisThe problem is when I run the installed application and am offline the telemetry is captured just fine . Next time I open the app when I 'm online ...
App Insights Telemetry not sending when offline
C_sharp : I am trying to develop an algorithm in C # that can take an array list of URL 's and output them in an outline numbered list.As you can imagine I need some help . Does anyone have any suggestions on the logic to use to generate this list ? Example Output : ... and so on <code> 1 - http : //www.example.com/abo...
c # outline numbering
C_sharp : I have function which serialize objects . It is working fine in every case except when I run with specific object . This is object of class which contains Tasks . But I do n't see why would this be problem.In debug mode code is just stuck without any error , or any exception . Just stop and waiting for ever.A...
SerializeObject is waiting for ever
C_sharp : I have this code ( the unimportant details are that it runs on EC2 instances in AWS , processing messages on an SQS queue ) .The first statement in the method gets some data over http , the second statement saves state to a local dynamo data store.The performance characteristics are that the http round trip t...
Should I make a fast operation async if the method is already async
C_sharp : Our code base has a lot of StringBuilder.AppendFormats that have strings that end with newline characters . I 've made an extension method called AppendLineFormat and would like to use Resharper 's Custom Patterns feature to identify and fix those old calls to use the new extension method ( and to suggest thi...
Can I use regex to find strings in Resharper 's Custom Patterns ?
C_sharp : I have a VC++ COM component with a type library . The type library of this component declares an interface and a co-class : In order to consume the component from a C # application I add a reference to the C # project and an interop assembly is generated.In the Object Browser of Visual Studio 2003 I see that ...
Names in the interop assembly have wrong capitalization
C_sharp : My Application can perform 5 business functions . I now have a requirement to build this into the licensing model for the application.My idea is to ship a `` keyfile '' with the application . The file should contain some encrypted data about which functions are enabled in the application and which are not . I...
How can I secure an `` enabled functions '' license file for my program ?
C_sharp : Good day ! I allow my content editors to store CSS as very basic components ( usually containing a single , multi-line field called `` code '' that they paste into ) , and these are then added as Component Presentations into a Page with a .css file extension . When creating the page , users are able to set a ...
Tridion 2011 : Changing a page 's file name as it 's being published
C_sharp : I found this bit of code that computes Levenshtein 's distance between an answer and a guess : But I need a way to do a count for the amount of times each error occurs . Is there an easy way to implement that ? <code> int CheckErrors ( string Answer , string Guess ) { int [ , ] d = new int [ Answer.Length + 1...
Levenshtein distance c # count error type
C_sharp : I have the following code : I want to write one function that will properly trim the fields , something like : Of course , this is not permitted in C # .One option I have is to write a helper and use reflection.Is there another way I can achieve this ( reflecting on so many properties will deffinitely have a ...
Modify multiple string fields
C_sharp : I was writing some code today and was mid line when I alt-tabbed away to a screen on my other monitor to check something . When I looked back , ReSharper had colored the 3rd line below grey with the note `` Value assigned is not used in any execution path '' . I was confused ; surely this code ca n't compile ...
Why is `` someString += AnotherString = someString ; '' valid in C #
C_sharp : If JavaScript 's Number and C # 's double are specified the same ( IEEE 754 ) , why are numbers with many significant digits handled differently ? I am not concerned with the fact that IEEE 754 can not represent the number 1234123412341234123 . I am concerned with the fact that the two implementations do not ...
Why are numbers with many significant digits handled differently in C # and JavaScript ?
C_sharp : I need to replace some parts of a string with each other using C # .I could find only one similar question about how to achive this here but it was PHP.My situation involves a Dictionary [ string , string ] which holds pairs to replace like : dog , cat cat , mouse , mouse , raptorAnd I have a string with the ...
How to replace two or more strings with each other ?
C_sharp : The following code finds instances of the word `` Family '' in a Word document . It selects and deletes the instances . The code works fine , but I want to find all instances of only highlighted words . <code> public void FindHighlightedText ( ) { const string filePath = `` D : \\COM16_Duke Energy.doc '' ; va...
Find highlighted text
C_sharp : I have an int array in one dimension : and I want to convert it to two dimensions , such as : How do I achieve this with C # ? <code> var intArray=new [ ] { 1 , 2 , 3 , 4 , 5 , 6 } ; var intArray2D=new [ , ] { { 1 , 2 } , { 3 , 4 } , { 5 , 6 } } ;
How to Convert int [ ] to int [ , ] - C #