text
stringlengths
46
37.3k
title
stringlengths
12
162
C_sharp : I 'm a student and i 'm new around here . I have a course project to make a Paint-like program . I have a base class Shape with DrawSelf , Contains ect . methods and classes for Rectangle , Ellipse and Triangle for now . Also i have two other classed DisplayProccesor which is class for drawing , and DialogPro...
When rotating shape , it stays together with the rotated one
C_sharp : On my production server I have set environment variable by adding the following to /etc/environment : I checked it has recorded with printenv ASPNETCORE_ENVIRONMENT after a reboot.My server is Ubuntu 14.04 and I am using asp.net core 1.1.It is loading my appsettings.Development.json instead of appsettings.Pro...
Ca n't set production server to production
C_sharp : Is it true that if i use the following , it will take less resources and the cleanup will be faster ? as compared to : <code> using ( TextReader readLogs = File.OpenText ( `` C : \\FlashAuto\\Temp\\log.txt '' ) ) { //my stuff } TextReader readLogs = new StreamReader ( `` C : \\FlashAuto\\Temp\\log.txt '' ) ; ...
using keyword takes less space ?
C_sharp : There are several options when one class must have a container ( collection ) of some sort of objects and I was wondering what implementation I shall prefer.Here follow the options I found : Pros : AClass is not dependent on a concrete implementation of a collection ( in this case List ) .Cons : AClass does n...
Having a collection in class
C_sharp : We have a problem with AppFabric that is causing the below error to occur : This error happens infrequently in our test environment ( we have not found a scenario to reproduce the issue on demand ) , but seems to always happen in our production environment just after each deployment . Our deployments are auto...
AppFabric CreateRoutingClient Error
C_sharp : I have IdentityServer4 with Angular . Every 5 minutes the token is silent refreshed . But after 30minutes the user is automatically logged out . I was trying to set lifetime cookies somehow , without any success . This is my current configuration : @ EDITIf I will addThen it working fine , but I bet this is n...
IdentityServer4 automatically logout after 30 minutes
C_sharp : Hey , I 'm self-learning about bitwise , and I saw somewhere in the internet that arithmetic shift ( > > ) by one halfs a number . I wanted to test it : Another Example : Thanks . <code> 44 > > 1 returns 22 , ok22 > > 1 returns 11 , ok11 > > 1 returns 5 , and not 5.5 , why ? 255 > > 1 returns 127127 > > 1 ret...
Why arithmetic shift halfs a number only in SOME incidents ?
C_sharp : I have a .NET Core worker project and want to add a library providing several HTTP endpoints . I have to stay with the worker project , I ca n't change it to a Web API project . What I have done so far : I created a worker projectI created a library projectI added a reference to the library in the worker proj...
register Web API controller from class library
C_sharp : I am trying to convert the ffg : ,This Worksinto this , which does not work , It gives me an error that it can not find `` COLUMNS '' .While debugging , it seems that rs is picking up all the return methods and private variables in the SELECT class it just is not picking up the method like COLUMNS in the SELE...
Dynamic object not showing its methods
C_sharp : I work in C # , so I 've posted this under C # although this may be a question that can be answered in any programming language.Sometimes I will create a method that will do something such as log a user into a website . Often times I return a boolean from the method , but this often causes problems because a ...
Methods that return meaningful return values
C_sharp : Consider the following code : I 'm trying to keep an instance of a generic class in a property for later usage , but as you know : Properties , events , constructors etc ca n't be generic - only methods and types can be generic . Most of the time that 's not a problem , but I agree that sometimes it 's a pain...
Using dynamic type instead of none-possible generic properties
C_sharp : How does the compiler handle interpolated strings without an expressions ? Will it still try to format the string ? How does the compiled code differ from that of one with an expression ? <code> string output = $ '' Hello World '' ;
How does C # string interpolation without an expression compile ?
C_sharp : Anyone have any ideas why this does n't work ( C # or VB.NET or other .NET language does n't matter ) . This is a very simplified example of my problem ( sorry for VB.NET ) : If you do : You will be surprised at the result . It will print `` Nothing '' . Anyone have any idea why it does n't print `` Something...
Interesting Property Behavior
C_sharp : Say I have a rather expensive assertion : If I test this assertion with : Will IsCompatible be executed in release builds ? My understanding is that Debug.Assert being marked as [ Conditional ( `` DEBUG '' ) ] , calls to it will only be emitted in debug builds . I 'm thinking that this wo n't prevent the expr...
Will the expression provided to Debug.Assert be evaluated in a release build ?
C_sharp : This code fails only in Release mode at Assert.Fail ( ) line despite the fact relay variable is still in scope and thus we still have strong reference to the instance , so WeakReference must not be dead yet.UPD : To clarify a bit : I realize that it can be 'optimized away ' . But depending on this optimizatio...
Is it really a bug in JIT optimization or am I missing something ?
C_sharp : There are multiple questions ( 1,2,3,4 etc . etc . ) called `` Why is n't this exception caught '' . Sadly , none of these solutions work for me ... So I am stuck with a truly uncatchable exception.I have a piece of code ( .NET 4.0 ) that checks a large textfile for digits and numbers . Whilst testing I got a...
Moby Dick of exceptions
C_sharp : I 'm new to C # and working on a snake project . I 'm trying to make it rainbow coloured , is there a better way to switch between six colours and then repeat ? Any suggestions ? <code> public Brush Colour ( int i ) { Brush snakeColour ; switch ( i ) { case 0 : case 6 : case 12 : case 18 : case 24 : snakeColo...
Better way to switch Brush colours ?
C_sharp : When using extremely short-lived objects that I only need to call one method on , I 'm inclined to chain the method call directly to new . A very common example of this is something like the following : The point here is that I have no need for the Regex object after I 've done the one replacement , and I lik...
Any reason not to use ` new object ( ) .foo ( ) ` ?
C_sharp : Compiler warning CS4014 ( calling async method without awaiting result ) is not emitted as a warning during build when the called method is in a referenced assembly.When the called method is in the same assembly the warning is correctly emitted.The compiler warning is signaled in Visual Studio when both proje...
Compiler warning CS4014 not emitted during build
C_sharp : Most of the Q & A I found on StackOverflow is how Binding work but x : Bind does n't which usually solved by Bindings.Update ( ) . However , my issue is , inside a GridView , ItemSource= '' { x : Bind _myList } '' works but ItemSource= '' { Binding _myList } '' does n't . Why ? And how do I make Binding work ...
x : Bind works but Binding does n't ( opposite to most Q & A found )
C_sharp : If you compile the following code : And then decompile it ( I used dotPeek ) and examine the all-important MoveNext method , you will see a bool variable declared near the beginning ; dotPeek chose `` flag '' for me.In this case , you will see one subsequent consumer of that variable , in the default case sta...
Why does a bool `` flag '' get generated for the async/await state machine ?
C_sharp : First , I apologize if this is not an appropriate venue to ask this question , but I was n't really sure where else to get input from.I have created an early version of a .NET object persistence library . Its features are : A very simple interface for persistence of POCOs.The main thing : support for just abo...
Is my idea for an object persistence library useful ?
C_sharp : I am trying to write a code generator using a c # console application . Now when I type this , I receive an error : It says `` input in wrong format '' I have checked that all the variables were strings , and they are . When I tried It worked perfectly fine . Is there a way to fix this ? <code> Console.WriteL...
Writing scope ( { ) into string in console app
C_sharp : Today , I was doing some tests in .NET Core , and I have come across some interesting thing.Before ( ~ .NET Framework 4 ) , Random used Environment.TickCount , but now I believe this has changed.Consider the following code : In older .NET Framework versions , the new Random ( ) empty constructor would use Env...
Did Microsoft change Random default seed ?
C_sharp : I was playing around with the C # compiler on TryRoslyn recently , and I came across a strange problem where an inequality check was getting converted into a greater-than one . Here is the repro code : and here is the code that gets generated by the decompiler : Here 's the link to the repro . Why does Roslyn...
Why is Roslyn generating a > comparison instead of a ! = one here ?
C_sharp : I just wrote an if statement in the lines ofand it annoys me that I always have to repeat the 'value == ' part . In my opinion this is serving no purpose other than making it difficult to read.I wrote the following ExtensionMethod that should make above scenario more readable : Now I can simply writeIs this a...
Is this a good use of an ExtensionMethod ?
C_sharp : Let 's assume that I have a controller 's action which does the following : checks if there is a calendar slot at a particular timechecks if there are no appointments already booked that overlap with that slotif both conditions are satisfied it creates a new appointment at the given timeThe trivial implementa...
Enforcing business rules in entity framework core
C_sharp : I 've got some inheritance going , requiring a custom JsonConverter for deserialization . I 'm using a very straightforward approach for now where I determine the type based on the existence of certain properties.Important note : in my actual code I can not touch the DeserializeObject calls , i.e . I can not ...
How to deserialize a list of abstract items without passing converters to DeserializeObject ?
C_sharp : I have a list of ranges . Each range has a from and to value , meaning the value can be between that range . For eample if range is ( 1,4 ) . , the values can be 1,2,3 and 4 . Now , I need to find the distinct values in a given list of range . Below is the sample code.I can loop through every range and find t...
Efficient Logic to get distinct values from a range of values in c # 2.0
C_sharp : I 'd like to reinterpret a string in a array of int where every int take charge of 4 or 8 chars based on processor architecture.Is there a way to achieve this in a relatively inexpensive way ? I tried out this but does n't seem to reinterpret 4 chars in one intSOLUTION : ( change Int64 or Int32 based on your ...
reinterpret cast an array from string to int
C_sharp : I 'm trying to detect when mouse enters VS 2017 title bar , but I 've noticed that MouseEnter and MouseLeave events do n't work correctly . Event fires only when mouse enters child controls outlined by green rectangle on the screenshot below.The title bar is a DockPanel with some elements in it . I 've set it...
IsMouseOver returns false over some elements in a DockPanel
C_sharp : I have read that a 'BackgroundWorker ' is designed to be replaced by Ansyc/Await . Because I like the condensed look of Async/Await , I am starting to convert some of my BackgroundWorkers into Async/Await calls.This is an example of the code I have ( called from the UI ) : When I call RunFromTheUI it will ret...
Does an await make the rest of the method asynchronous ?
C_sharp : I am trying to define code contracts for an interface using ContractClass and ContractClassFor . It works fine when everything is in the same assembly , but if I put the interface definition and its respective contract class in a different assembly then the concrete class implementation , it does n't work any...
Code Contracts for C # does not work when ContractFor is on a different assembly
C_sharp : IntroductionAs a developer , I 'm involved in writing a lot of mathematical code everyday and I 'd like to add very few syntactic sugar to the C # language to ease code writing and reviewing.I 've already read about this thread and this other one for possible solutions and would simply like to know which best...
Extending C # language , how much effort/gain ?
C_sharp : As in : And how do I search for it in the documentation ? <code> public string [ , ] GetHelp ( ) { return new string [ , ] { ... things ... } }
What does [ , ] mean in c # ?
C_sharp : I 'm working on my solution to the Cult of the Bound Variable problem.Part of the problem has you implement an interpreter for the `` ancient '' Universal Machine . I 've implemented an intepreter for the machine they describe and now I 'm running a benchmark program that the university provided to test it.My...
How can I speed up array cloning in C # ?
C_sharp : I 'm using Visual Studio 2015 on Windows 10 , I 'm still a new coder , I 've just started to learn C # , and while I was in the process , I discovered the Math class and was just having fun with it , till the console outputted : `` ∞ `` It 's a Console ApplicationHere 's the code : Why is this happening ? usi...
C # : The console is outputting infinite ( ∞ )
C_sharp : I bet that 's an easy question for you , but searching SO or Google with { or } in the search string does n't work very well.So , let 's say i wan na output { Hello World } , how do i do this using string.format ( ... ) ? Edit : looks like this : would do the job , but that does n't look very elegant to me . ...
Output ' { ' or ' } ' with string.format ( ... )
C_sharp : I have an ID with me and I have name with me . So in essence , my method just has these parameters : and I have this piece of logic inside method : That 's it . Nothing fancy . I get this error : `` An object with the same key already exists in the ObjectStateManager . The ObjectStateManager can not track mul...
Why I do I fall into all of the hurdles for a simple update in EF ?
C_sharp : When we have two structs , and one is implicitly convertible to the other , then it seems like the System.Nullable < > versions of the two are also implicitly convertible . Like , if struct A has an implicit conversion to struct B , then A ? converts to B ? as well.Here is an example : Inside some method : In...
`` Covariance '' of the System.Nullable < > struct
C_sharp : I 'm trying to match strings that look like this : But not if it occurs in larger context like this : The regex I 've got that does the job in a couple different RegEx engines I 've tested ( PHP , ActionScript ) looks like this : You can see it working here : http : //regexr.com ? 36g0eThe problem is that tha...
RegEx does n't work with .NET , but does with other RegEx implementations
C_sharp : As you can see in the following image , I have a model with a base class `` Person '' and both entities `` Kunde '' and `` Techniker '' inherit the base class.Now I 've got following problem . When I try to use the method Find to get an object of the derived class Kunde with given ID , it tells me that OfType...
Finding inherited object by ID - Entity Framework
C_sharp : I 'm trying to learn how to use WPF binding and the MVVM architecture . I 'm running into some trouble with Dependency Properties . I 've tried to control the visibility of an item on the view by binding it to a DependencyProperty in the DataContext , but it does n't work . No matter what I set the GridVisibl...
WPF Data Binding Architecture Question
C_sharp : I 'm trying to create an instance of a generic class , without knowing what type to cast it to it until runtime . I 've written the following codeHopefully that gives you an idea what I 'm trying to do , however it wont compile it just says `` the type or namespace pType could not be found '' . Is there any e...
C # Generics
C_sharp : I have a very basic video recording project that was working perfectly in Swift , but the same code ported into a blank project in Xamarin is producing a video that is constantly skipping frames every few seconds . The code starts in ViewDidLoad and is stopped via a UIButton Here is the recording code below :...
Video produced by ReplayKit is constantly skipping frames in Xamarin
C_sharp : I 'm trying to use reflection to retrieve a list of all methods of an interface + its base interfaces.So far I have this : I 'd like to be able to filter out methods that shadow methods declared in base interfaces , i.e. , `` new '' methods : With my current code , the result includes both methods - I 'd like...
How to check whether an interface 's MethodInfo is a `` new '' method
C_sharp : I have this BdlTabItem which receives a parameter of type DockableUserControl and would like to know if is it a bad practice to create a circular reference between the two by using uc.TabItem = this and new BdlDockableWindow ( this ) before the constructor finishes.I know this behavior can be considered reall...
Is it a bad practice to pass `` this '' as parameter inside its own constructor ?
C_sharp : I have some objects that read a file , save the data in arrays and make some operations . The sequence is Create object A , operate with object A . Create object B , operate with object B ... The data read by each object may be around 10 MB . So the best option would be to delete each object after operate wit...
Need to delete objects : implement Dispose or create objects in a function ?
C_sharp : I have the following block of linq queries to calculate some values for a report.I 've stepped through the code in a debugger and I 've noticed some oddities . After assigning into test its value is 0 . After assigning into test2 test2 == 0 and test == 11.31 after assigning into test3 test == 11.31 test2 == 1...
Why do n't the values from my linq queries appear immediately ?
C_sharp : EDITIf I use Stopwatch correctly and up the number of iterations by two orders of magnitude I getTernary took 22404msNormal took 21403msThese results are closer to what I was expecting and make me feel all is right with the world ( if not with my code . ) The Ternary/Conditional operator is in fact marginally...
Why does the conditional ( ternary ) operator seem significantly faster ?
C_sharp : I have ICollectionView looks like I want to use drag & drop to change the item Series Name , and location on the list view any idea how to do that for example if Idraged and droped book3 in ScienceFiction the output should be I use xaml code like this : <code> public ICollectionView UsersCollectionView { get ...
change the group of item in ICollectionView
C_sharp : Is there a performance difference between the following two pieces of code ? andMy gut feeling is that the compiler should optimize for this and there should n't be a difference , but I frequently see it done both ways throughout our code . I 'd like to know if it comes down to a matter of preference and read...
Is there a performance difference by excluding an 'Else ' clause ?
C_sharp : Situation : Assembly 1 is a application that other developers can use.We will give them only the .dll so we can publish updates from the application if we do n't change the api . The developers ca n't change the framework in assembly 1Methods are virtual so developers can override methods to implement there o...
C # OO design problem with override from methods
C_sharp : I 'm trying to write a complement function , such that when provided with a function f , it returns a function which , when provided with the same input as f , returns it 's logical opposite.Having put similar code into VS2017 , I get no errors , however I 'm not yet able to run the code to see if it 'll work...
Complement higher order function
C_sharp : I would like to write a method that gives me the 3 letters - representing the day , month , year - from a datetimeformat.So in en-US culture my desired return values would be ( plus the separator ) dMy/in de-DE the same method should returnT ( Tag = day ) M ( Monat = month ) J ( Jahr = year ) . ( Separator ) ...
DateTime get the letters representing day , month , year from the currentculture
C_sharp : I found interesting behavior of LinkedList < T > . I ca n't call Add method for an instance of LinkedList < > . However LinkedList < T > implements ICollection < T > ( link ) which actually has the Add method . Here are examples . When I do like this , it works perfect : But this code even will not compile : ...
LinkedList does not contain explicit Add method
C_sharp : I know I can create expression trees using : Factory methods.Compiler conversion of a lambda expression to an Expression.For complicated expression trees I would prefer 2 because it is more concise.Is it possible to refer to already constructed Expressions using this way ? <code> using System ; using System.L...
Using an Expression in a compiler-generated expression tree
C_sharp : In one class , ClassA , I have a timer object . In this class I register the event handlers for the timer elapsed event . In another class , ClassB , I have a public event-handler for the timer elapsed event . So I register the event-handler from ClassB in ClassA as follows : What happens if I were to create ...
What happens when an event fires and tries to execute an event-handler in an object that no longer exists ?
C_sharp : Sorry about the vocabulary question but I ca n't find this anywhere : how do you call this below ? Is it a statement , a directive , ... ? I want to indicate that you have to insert that line in order to give MyAssembly access to your assembly 's internal members , but I 'd like to use a more specific term th...
What is [ assembly : InternalsVisibleTo ( `` MyAssembly '' ) ] ? A statement , directive , ... ?
C_sharp : I wonder what the difference is between the following methods with regards to how the object parameter is referenced : andShould I use ref object parameter in cases where I want to change the reference to the object not override the object in the same reference ? <code> public void DoSomething ( object parame...
What is the difference between 2 methods with ref object par and without ?
C_sharp : While analyzing the .NET memory allocation of my code with the Visual Studio 2013 performance wizard I noticed a certain function allocating a lot of bytes ( since it is called in a large loop ) . But looking at the function highlighted in the profiling report I did n't understand why it was allocating any me...
non executing linq causing memory allocation C #
C_sharp : I 'm trying to refactor some code to use .NET Core dependency injection via mapping services in startup.cs . I would like to inject an IRequestDatabaseLogger here instead of newing it up . However it requires the context in the constructor . How can I achieve this ? Is it even possible without an DI framework...
Injecting a logger with constructor dependencies
C_sharp : I 'm trying to create a generic method that will return a predicate to find elements in an XML document . Basically something like this : Only thing is that this does n't compile . The problem is on the ( T ) x.Attribute ( criterion.PropertyName ) part where the compiler indicates : Can not cast expression of...
Is there a way to do this kind of casting in a c # predicate
C_sharp : I 've been working , giving up and then reworking on this problem for a couple days . I 've looked at a lot of different ways to go about however I either ca n't implement it correctly or it does n't suit what I need it to do.Basically : I have two arrays , prefix and suffix I need to : Have a minimum of 3 us...
C # OR Javascript Permutations of two arrays multiple times
C_sharp : I have been struggling with these elements for about 2 months . The first problem arise when my MVC4 application was recycled . The current logged-in user suddenly can not access any controller actions which are marked [ Authorize ] . Also , any successful access to the controller action which requires databa...
ASP.NET MVC : How do SimpleMembership , SQLSession store , Authentication , and Authorization work ?
C_sharp : I 'd like to arrange some TextBlocks horizontally without any margins . I can see that my TextBlock is as small as it should be , but for some reason a lot of space is added around it . I think it has something to do with the ListView or its styling , but I do n't know what.I have a following layout : <code> ...
Too much spacing between StackPanel items in Windows Store app
C_sharp : it 's possible write something like : C # there a equivalent to .apply of javascript ? <code> function foo ( a , b , c ) { return a + b + c ; } var args = [ 2,4,6 ] ; var output = foo.apply ( this , args ) ; // 12
dynamic arguments definition in C #
C_sharp : I 've been reading Jon Skeet 's C # In Depth : Second Edition and I noticed something slightly different in one of his examples from something I do myself.He has something similar to the following : Whereas I 've been doing the following : Is there any real difference between the two ? I know Jon Skeet is pre...
Linq with dot notation - which is better form or what 's the difference between these two ?
C_sharp : I need a data structure with both named column and row . For example : I need to be able to access elements like magic_data_table [ `` row_foo '' , `` col_bar '' ] ( which will give me 3 ) I also need to be able to add new columns like : AFAIK , DataTable only has named column ... EDIT : I do n't need to chan...
Is there a `` DataTable '' with `` named row '' in C # ?
C_sharp : Robert C. Martin in one of his talks about clean architecture openly criticizes fairly standard way of doing things nowadays.Robert C. Martin - Clean Architecture and DesignWhat I understand as standard way is something like this : Martin here says , that the application should reveal its purpose immediately ...
How can a top level directory structure reveal the purpose of the application ?
C_sharp : I 'm trying to replace CompilationUnitSyntax of a class using Roslyn.However , ReplaceNode that I 'm using has a different signature than ReplaceNode in Roslyn FAQ and any StackOverflow question that I 've looked at . Can anyone point out why is that , and how can I use ReplaceNode that takes old ClassDeclara...
Ambiguity in Roslyn 's CompilationUnitSyntax.ReplaceNode
C_sharp : I have a list like so : and each element of the string array is another array with 3 elements.So countryList [ 0 ] might contain the array : How can I search countryList for a specific array e.g . how to search countryList for <code> List < string [ ] > countryList new string [ 3 ] { `` GB '' , `` United King...
How to search a list in C #
C_sharp : I would like to implement my generic IQueue < T > interface in an efficient way by doing one implementation if T is struct and another if T is a class.The , I 'd like to have a factory method which based on T 's kind returns an instance of one or the other : Of course , the compiler indicates that T should be...
Chose generic implementation if the type parameter is struct or class
C_sharp : I have a form that i dynamicly compiled and i have a style class . When i copy this style class to my form source and compile it all works fine . But how can i use this style class without copy it to my form source . My main program that compile this form has this class , how can i use it ? Maybe i can pass s...
How to use custom class with dynamic compilation
C_sharp : I have a function which among other things does a conversion from Utc to Local and vice-versa.The problem is that when I run it on a PC with Win 7 it works OK , but when I run it on a PC with Vista the conversion goes wrong.ex : My current time zone is +2 UTCMyCurrentTime is set to 27.09.2012 , 19:00 and the ...
DateTime conversion from Utc to Local in .NET 4.0
C_sharp : I have a vector class with two deconstruction methods as follows : Somewhere else I have : This gives me : How is this ambiguous ? Edit : Calling Deconstruct manually works fine : <code> public readonly struct Vector2 { public readonly double X , Y ; ... public void Deconstruct ( out double x , out double y )...
Deconstruction is ambiguous
C_sharp : I have some user admin functionality in a WPF app that I 'm currently writing and would like to make it a bit more intuitive for the end userI 'd like to be able to provide some kind of means of easily editing the list of roles a given user belongs to . At the moment the grid is filled as a result of binding ...
Enhancing the display of a particular column in a WPF grid view
C_sharp : I have two arrays , one with values an one with indicesnow I want a result array from the items selected by the indices of indices arrayQuestion : Is there a more generic approach for this ? <code> int [ ] items = { 1 , 2 , 3 , 7 , 8 , 9 , 13 , 16 , 19 , 23 , 25 , 26 , 29 , 31 , 35 , 36 , 39 , 45 } ; int [ ] ...
Get array items by index
C_sharp : Let 's say I have a service interface that looks like this : I would like to fulfill some cross-cutting concerns when calling methods on services like these ; for example , I want unified request logging , performance logging , and error handling . My approach is to have a common base `` Repository ' class wi...
Why is n't type inference working in this code ?
C_sharp : How can we access the complete visual studio solution from code analyzer in Roslyn ? I have been trying semantic analysis without much help.This is what I came up with using intellisense but this always gives a null value . <code> var sol = ( ( Microsoft.CodeAnalysis.Diagnostics.WorkspaceAnalyzerOptions ) con...
Accessing VS complete solution in roslyn
C_sharp : I 'm generating a file on the fly on the event of a button . I have to following code : I would like the Save As Dialog to appear after the first flush , because the operation can take a while . How would I go about ? After some playing around I discovered that it will buffer 256 characters ( reproducible by ...
How to make a save as dialog appear `` early '' ? Or : How to make Flush ( ) behave correctly ?
C_sharp : I have a checkbox substituting a switch-like control.It works great . The only problem is that this checkbox initial mode can be either true or false . For false - no problem , but if it 's true , then when the view is loaded , you immediately see the animation of the switch moving . I want to prevent that . ...
Pause/prevent animation for a checkbox control
C_sharp : Consider the following code that I 'm using when displaying a Customer 's mailing address inside a table in a view : I find myself using a fair amount of these ternary conditional statements and I am wondering if there is a way to refer back to the object being evaluated in the condition so that I can use it ...
ASP.NET MVC/C # : Can I avoid repeating myself in a one-line C # conditional statement ?
C_sharp : If I compile the following code snippet with Visual C # 2010 I ALWAYS get false : Does anybody know why ? ? ? <code> object o = null ; Console.WriteLine ( `` Is null : `` + o == null ) ; // returns false
Testing for null reference always returns false ... even when null
C_sharp : In ASP.NET Core you can validate all non-GET requests by including this line in Startup.cs ( docs ) : However , if you add the filter by type ( using typeof or the generic Add < T > method ) , the validation does n't seem to work : See https : //github.com/davidgruar/GlobalFilterDemo for a minimal repro.What ...
Why does adding AutoValidateAntiForgeryTokenAttribute by type not work ?
C_sharp : The following Rx.NET code will use up about 500 MB of memory after about 10 seconds on my machine.If I use the Observable.Generate overload without a Func < int , TimeSpan > parameter my memory usage plateaus at 35 MB.It seems to only be a problem when using SelectMany ( ) or Merge ( ) extension methods . <co...
Why does this Observable.Generate overload cause a memory leak ? [ Using Timespan < 15ms ]
C_sharp : I 'm trying to get the positions of controls ( buttons ) but it keeps returning { 0 ; 0 } . I 'm sure there 's an explanation for this , but I ca n't figure out why this happens.I want the position of the control , relative to the window or a certain container . My buttons are arranged in another grid . Takin...
WPF - Getting position of a control keeps returning { 0 ; 0 }
C_sharp : ReSharper has features that look for inconsistencies in the use of keywords aliasing a type name . For example , it would see these two declarations and urge you to change one to be like the other ( depending on which is set as your preference ) : This is handy , because I always prefer using the keyword alia...
Can ReSharper use keyword for declarations but type name for member access ?
C_sharp : I know and I think I understand about the ( co/conta ) variance issue with IEnumerables . However I thought the following code would not be affected by it.This class is to mimic BackgroundWorker 's RunWorkerCompletedEventArgs so I can return errors from my WCF service without faulting the connection.Most of m...
Implicit cast fails for myClass < T > when T is IEnumerable < U >
C_sharp : Is there a way of calling a method/lines of code multiple times not using a for/foreach/while loop ? For example , if I were to use to for loop : The lines of code I 'm calling do n't use ' i ' and in my opinion the whole loop declaration hides what I 'm trying to do . This is the same for a foreach.I was won...
Looping through a method without for/foreach/while
C_sharp : We have a lot of code that passes about “ Ids ” of data rows ; these are mostly ints or guids . I could make this code safer by creating a different struct for the id of each database table . Then the type checker will help to find cases when the wrong ID is passed.E.g the Person table has a column calls Pers...
Is it a good idea to create a custom type for the primary key of each data table ?
C_sharp : I have a float4x4 struct which simply containts 16 floats : I want to copy an array of these structs into a big array of floats . This is as far as I know a 1:1 copy of a chunk of memoryWhat I do know is rather ugly , and not that fast : If I was using a lower level language , I would simply use memcpy , what...
Is there a faster/cleaner way to copy structs to an array in C # ?
C_sharp : Im trying to make a universal parser using generic type parameters , but i ca n't grasp the concept 100 % As you might guess , the code does n't compile , since i ca n't convert int|bool|string to T ( eg . value = valueInt ) . Thankful for feedback , it might not even be possible to way i 'm doing it . Using ...
Generic type parameters using out
C_sharp : I have a ( C # ) function that checks four sets of conditions and returns a bool . If any of them are true , it returns true . I 'm sure I could simplify the logic but I want it to be fairly readable.The CodeMaid extension in Visual Studios and tells me the cylomatic complexity of the function is 12 . I looke...
Why is the cylcomatic complexity of this function 12 ?
C_sharp : Why does the following compile ? It sure seems like the compiler has enough info to know that the attempted assignment is invalid , since the return type of the Func < > is not dynamic . <code> Func < dynamic , int > parseLength = whatever = > whatever.Length ; dynamic dynamicString = `` String with a length ...
Why does the compiler treat the return type of Func < dynamic , int > as strongly typed ?
C_sharp : I 'm trying to make a dynamic array in C # but I get an annoying error message . Here 's my code : And the error : This is just baffling my mind . I came from VB , so please me gentle , lol.Cheers . <code> private void Form1_Load ( object sender , EventArgs e ) { int [ ] dataArray ; Random random = new Random...
Ca n't make an array in C #
C_sharp : want to know why String behaves like value type while using ==.StringBuilder and String behaves differently with == operator . Thanks . <code> String s1 = `` Hello '' ; String s2 = `` Hello '' ; Console.WriteLine ( s1 == s2 ) ; // True ( why ? s1 and s2 are different ) Console.WriteLine ( s1.Equals ( s2 ) ) ;...
Why String behaves like value type while using ==
C_sharp : Currently working on a 2-way lookup association generic , sorted by TKey . At some point I hope to have access like the following : But obviously when TKey == TValue this will fail . Out of curiosity , is there a conditional compile syntax to do this : <code> public class Assoc < TKey , TValue > { public TKey...
Conditional Compile of Generic Methods
C_sharp : Programmers on my team sometimes open a transaction and forget to include the scope.Complete ( ) statement ( see code block below ) . Any ideas on ways to either ( 1 ) search our solution for missing scope.Complete ( ) statements , or ( 2 ) have Visual Studio automatically highlight or raise a warning for mis...
C # - How do I check for missing scope.Complete ( ) statements ?
C_sharp : How would I know what `` it '' means here ? Whole example from MSDN docs <code> productQuery1.SelectValue < Int32 > ( `` it.ProductID '' ) ; using ( AdventureWorksEntities context = new AdventureWorksEntities ( ) ) { string queryString = @ '' SELECT VALUE product FROM AdventureWorksEntities.Products AS produc...
Where does `` it '' come from in this example of ObjectSet < T > .SelectValue ?