text
stringlengths
46
37.3k
title
stringlengths
12
162
C_sharp : The following code snippet is extracted from Example 10-11 ( p. 343 ) from Programming C # 5.0 : I ca n't figure out how it could get compiled without exposing any information on T by applying constraints on it . Specifically , how could the compiler know how many bytes to allocate for the array , given that ...
Why should the generic code compile without constraining T ?
C_sharp : How can i get |ADT^A05| out of `` MSH|^~\ & |PHTADT09|ABC|DADIST00|ABC|20120425152829|rcalini1|ADT^A05|20429208851634|P|2.1|560 '' I have tried this but not working <code> `` | ( [ A-Z ] { 3 } ) ^ ( [ A-Z ] { 1 } ) ( [ 0-9 ] { 2 } ) | ''
regex get a match
C_sharp : Consider this example : How do I know if calling await BarB ( ) changes the context without reading the body of the async Task BarB ( ) function ? Do I really need to know exactly whether an async function calls ConfigureAwait ( false ) at any point ? Or maybe the example is wrong and there 's no exception ? ...
How do I know if an async method call changes the caller 's context ?
C_sharp : I 'm tying to find characters from given list for each word of string separately , but I ca n't figure out how in my case to get found character by order exist in word and keep repeated characters . For example , if list to find is : var findChar = new List < string > { `` a '' , `` i '' , `` t '' , `` e '' ,...
How to get found characters by order from string and keep duplicates to add it to the list without overwriting of previous
C_sharp : I was looking at some code that I am refactoring and notices the try ... catch code wraps quite a lot of code , not of all which would throw `` normal '' exceptions i.e . The code would n't throw at all or if it did it would be totally fatal exceptions like out of memory exceptions . What I am wondering now i...
Is try wrapping excess code acceptable ?
C_sharp : I am trying to implement Searching for a custom element in a list with a custom column name using a webservice for JQgrid , but I am out of ideas I would appreciate any help on this.I ca n't copy my code here but , for example , I have an entity like : and I created a function to return a list of this class :...
select an element from a custom column from a list
C_sharp : Ok , I need to test if two IEnumerable < T > are equal . The order of the elements is important , which means that : I 've seen a few answers on this site explaining how to do this with linq : for example , hereThe problem is that I have to repeatedly test for equality of pretty big collections ( thousands of...
Algorithm for testing inequality of ordered large collections
C_sharp : Considering the Method Declaration Like this : And then Calling it like this : What is the effect of @ before the method name ? Does it behave like putting it before a string which contains escaped characters ? <code> public void MethodName ( string param ) { // method body } obj . @ MethodName ( `` some stri...
Usage of @ Before Method Call
C_sharp : To order a list with Linq we have to call OrderBy first en call ThenBy on the result for subordinate orderings.I 'm in a situation now where I do not know the top level ordering before hand . I have a list of of orderings which should be applied conditionally.Like this : So the list will always be ordered by ...
order list where top level order is unknown
C_sharp : This is the obvious , easiest way to solve this problem . However , I 'd prefer not to use an unsafe method if I can avoid it . Basically , I have a bunch of integers which represent registers . There are assembly instructions that take register mnemonics as arguments . I 'd prefer not to have the logic to de...
Safe ( in the C # sense ) way to implement something with pointers
C_sharp : I have five paragraphs on my front end as below : In JS I wrote the following : I know when I click on the button it hides all the p tags , so it would be great if any one can tell me how I would be able to hide the third paragraph only . <code> < form id= '' form1 '' runat= '' server '' > < div id= '' div ''...
Hide the 3rd paragraph out of 5 paragraphs on a click of a button , with out assigning any class or id to the paragraphs
C_sharp : Here is some sample data : Background : The above uses a simplified version of a Book class . It would , of course , contain many fields . My end goal is to allow the user to perform an 'advanced ' search allowing the user to specify any field and further allow the user to specify keywords using boolean algeb...
Why do these three pieces of LINQ code produce different ( or erroneous ) results ?
C_sharp : I 'm wondering if I do something like this : Is this going to work ? By `` work '' I mean - will MethodA be unsubscribed from ExternalObject.Click event ? And other related questions : What happens behind the scenes when an instance method is used instead of delegate instance ? ( like above ) Does this cause ...
C # events and class methods
C_sharp : I have a database called ebookstore.db as below : and JSON as below : I want when slug on JSON is not the same as a title in the database , it will display the amount of data with a slug on JSON which is not same as a title in the database in ukomikText.Code : BukuUpdate.cs : I have a problem , that is when c...
UWP - Compare data on JSON and database
C_sharp : I am trying to mask a string name with * ( asterisks ) and exclude both the first and nth ( 5th ) characters.Example : UserFirstName - > U****F*******I managed to exclude the first character with ( ? ! ^ ) . : output : UserFirstName - > U************How can I also exclude the character in the 5th position ? <...
Regex Replace exclude first and nth character
C_sharp : I 'm doing a big refactor of a pile of code that used to use a bunch of multidimensional arrays that were constantly getting resized . I created a data object to replace the 2D array , and I 'm now passing a list of these around.I discovered something that worries me a little though . Let 's say I have some c...
Passing Collections Immutably
C_sharp : Today I see this code : And I can not understand . `` ~ '' - This is a mistake ? As far as I remember , `` ~ '' is placed before the destructors . But this is enum . And this code compiled ! <code> ViewBag.country = from p in CultureInfo.GetCultures ( CultureTypes.AllCultures & ~CultureTypes.NeutralCultures )...
What does `` ~ '' mean before enums
C_sharp : If I were to change the value of bool.TrueString , I 'd do it using Reflection : However , I can not manage to change the value of , say , Type.Delimiter : Why is this ? <code> typeof ( bool ) .GetField ( `` TrueString '' , BindingFlags.Public | BindingFlags.Static ) .SetValue ( null , `` Yes '' ) ; Console.W...
Why ca n't I change Type.Delimiter using Reflection ?
C_sharp : I have never done this before , and while I ca n't think of a specific reason that it would break , I 'd like to verify that it is valid to use an out variable as follows : <code> void Main ( ) { var types = new [ ] { typeof ( A ) , typeof ( B ) } ; bool b = false ; var q = from type in types from property in...
Is it safe to use out variables in calls within LINQ statements ?
C_sharp : I am looking at some code that a coworker wrote and what I expected to happen is n't . Here is the code : In another class , I would have expected to be able to do : and it reference the same Instance of that class . What happens is I can only have one .Instance . Something that I did not expect . If the Inst...
Trying to understand how static is working in this case
C_sharp : I have recently found an interesting behavior of C # compiler . Imagine an interface like this : Now if we do The compiler will complain that he does not know which overload to chose ( Ambiguous invocation ... ) . Seems logical , but when you try to do this : It will suddenly have no troubles figuring out tha...
Strange C # compiler behavior when choosing overload that looks like a bug/missing feature
C_sharp : I have a base class and several derived classes ( for example Base and ChildA : Base ) . Each time I create an instance of ChildA class , I want it to be assigned a unique instance number ( similar to autoincrement IDs in relational databases , but for my classes in memory as opposed to in a database ) .My qu...
BaseClass with instance counter
C_sharp : I have a Question for you guys.I have 2 unit tests which are calling webservices .The value that one unit-test returns should be used for another unit test methodExample How can i store a value in one unittest and use that value in another unittest . <code> namespace TestProject1 { public class UnitTest1 { St...
Holding a Value in Unit tests
C_sharp : I ca n't change this `` value '' variable from locals or immediate window.Whats wrong ? T is n't a int in runtime ? i ca n't change _value too.I think this is a bug or something ? Beside using this , tried to use instance of Just , worked fine <code> class Program { static void Main ( string [ ] args ) { Just...
Changing T type int in local window
C_sharp : I have a base class , say named B. I have two derived classes , D1 and D2.Looks like : Now , I created a new interface IDeepCopyable < T > which has one method Clone ( ) : I want to force each subclass too implement this interface with the base class ( i.e . IDeepCopyable < B > .If I try to leave B 's declara...
Can I Enforce a Subclass to Implement an Interface ?
C_sharp : In .NET , I understand that there is a garbage collector that will manage the memory that 's being used during the execution of a program . This means that objects will be cleaned up when they go unused.I was wondering if I could keep a static counter in a certain class that automatically updates when instanc...
Is is possible to keep track of the current number of instances of a class ?
C_sharp : I recently wrote a class library that includes some objects that model certain types of files . For example , there is an abstract Document class , with derived classes PdfDocument ( concrete ) and OfficeDocument ( abstract , with concrete derived classes such as WordDocument and ExcelDocument ) , etc.Current...
Who should be responsible for selecting the appropriate derived class ?
C_sharp : I 'm working on rewriting an MVC application that currently utilizes cookies to hold data between multiple pages such as a date . I have tried to come up with an option that would hold the data in the controller by using something like this : The problem that I 'm facing is that this is overwritten on each pa...
Holding value between multiple pages
C_sharp : I have an enum type which derives from byte . In my common library , at some point there is a cast of an enum parameter to int.The problem is when my byte derived enum gets to that method in the common library , the cast to int fails and raises an exception.Is there a way to type check an enum 's base class s...
How to Type check for enum instance base class ?
C_sharp : Basically I have a list of objects . Let 's call them meetings . Inside the meetings there is another list of objects . Let 's call those participants . I want to return all meetings where a certain participant is in the list.I want something like this : Basically return a list of meetings , where the meeting...
Extract list where string is contained inside a list inside the list
C_sharp : The following query does solve my problem however it seems overly complex.The problem is I have a table that stores menu options ( id , name , description and price ) . I also have a session variable that stores the users selections in a Dictionary ( storing id and quantity ) .The LINQ I 've produced below ba...
How to improve my LINQ
C_sharp : i 'm trying to make this code works in async way , but i got some doubts.I got some string input collection , and i would like to run this method on them.Then i would do Task.WhenAll , and filter for non empty strings.But it wo n't be async as inside the method i 'm already awaiting for the result right ? <co...
C # TaskWhenAll on method which is returing result depending on awaited call
C_sharp : If I have made a variable of a non-reference type , say int , nullable , i.e . int ? , does this mean I need to use a constructor before assigning a value ? Normally to intialise a non-reference type variable I simply doBut if I have a nullable non-reference data type variable is initialisation neccessary , a...
Is new ( ) required for nullable non-reference type variable ?
C_sharp : I have a somewhat complicated Class that may or may not contain a list of items of the same typeThe class itself is serializeable , however its going to be a giant waste of space to serialize the objects in the list since they are serialized and added to the database prior to being included in the list.Is the...
Specify how to Serialize my object if it is in a list
C_sharp : Consider this : ... and this : The first example compiles , the second does n't . To use a nested type reference when inheriting from a generic type I must qualify it with the parent 's type name : My question is , why ? and why does n't this restriction apply when referring from an attribute in the parent ty...
Why do I have to parent-type-qualify to use a nested type when inheriting from a generic type ?
C_sharp : If I have a string variable with value as follows : -and I want to manipulate this string and make it as follows : -ie I want to just remove all the duplicates in it , how should I do it ? Please help . Thanks . <code> string mystring = `` TYPE1 , TYPE1 , TYPE2 , TYPE2 , TYPE3 , TYPE3 , TYPE4 , TYPE4 '' ; str...
Manipulate string problem
C_sharp : Why does the code below display ' ? ' instead of ' $ ' ? The result is : 29,56 ? <code> static void Main ( string [ ] args ) { float price = 29.56f ; Console.WriteLine ( price.ToString ( `` c '' ) ) ; }
Why is the currency modifier `` C '' returning ' ? ' instead of ' $ ' in C # ?
C_sharp : This is a rather educational , out of curiosity question . Consider the following snippet : Where SubscribeDebug subscribes a simple observer : The output of this is : Value : 0Value : 1Value : 2Value : 3Value : 4And then blocks . Can someone help me understand the underlying reason why it happens and why the...
Why does repeated Enumerable to Observable conversion block
C_sharp : Hi I am new to C # and have been learning it . Actually think I am getting use to it there are a few things which I am unsure about but will try to research them before asking . That said one thing I can not find it collections . I come from a VB.NET back ground and previously I used collections of another cl...
Collections in C # over VB.NET
C_sharp : I have an XML document from which I need to extract a nodeset and add a namespace . So , from a doc I extract this : and need to create this : There will be a variable quantity of list items and the elements might change and have different name , so I need a generic solution.Is there an easy way to do that in...
Changing XML using .Net
C_sharp : I 'm building the following class : What I need is to make T be the type of child Foo class : Is it achievable ? If so , how ? <code> abstract class Foo { protected abstract void Process ( FooProcessor < T > processor ) } class FooChild : Foo { protected override void Process ( FooProcessor < FooChild > proce...
Self generic type
C_sharp : I am experiencing a weird behaviour from Visual Studio 2013 . I 've got a C # program which writes to the standard output , let 's sayIn the Debug tab of the project 's properties I have redirected the output to a file , like this : If I open the file within those 10s when my application is still running , th...
Visual Studio clears output file at end of debugging
C_sharp : Essentially what I want to do is impliment a class that can contain a list of references to instances of the same type . Something like the following : I know this wo n't compile because the interface explicitly says my Settings must be of the type List < IAccessibilityFeature > . What I am after is some guid...
Can you define an interface such that a class that implements it must contain a member that is also of that class ?
C_sharp : First of all “ A method group is a set of overloaded methods resulting from a member lookup ” . In my example I use the set of Console.WriteLine methods with 19 overloads.The definition of a method group in C # Language Specification also states that : “ A method group is permitted in an invocation-expression...
Why are the methods groups allowed on the left-side of ‘ is ’ operator and how can this be used in practice ?
C_sharp : I 'm writing a method to generate a DataTable taking as datasource a generic IEnumerable . I am trying to set a default value on the field if theres no value , with the code below : It 's throwing this error : The type or namespace name 'typeAux ' , could not be found ( are you missing a using directive or an...
Why is n't this code compiling ?
C_sharp : We have a legacy .NET solution which has a combination of MVC and WebForms stuff , and some Web API projects as applications under the website root . Obviously these Web API applications will inherit the website 's web.config settings.We also have another project - a bounded context - for SSO authentication w...
Blocking web.config inheritance in a sub-application
C_sharp : Below code compiles in VS2015.2 , but after upgrade to VS2015.3 it fails with error CS0019 : Operator '== ' can not be applied to operands of type 'Registration < Something > ' and 'Something'.I can not find any notice about such a change in the changelog for update 3 . Can someone tell me , why this happens ...
Combination of implicit conversion , equality operator and nullables fails to compile after update from Visual Studio 2015.2 to 2015.3
C_sharp : In the following code , are the using blocks redundant or are they necessay to fully release resources ? <code> using ( var dialog = new AboutBox ( ) ) dialog.ShowDialog ( ) ; using ( var form = new OptionForm ( ) ) form.Show ( ) ;
It is redundant to wrap dialogs in using blocks ?
C_sharp : I am developing a software that takes realtime-data and extracts a number of features from that depending on user input . Each available feature consists of one method that takes an array of doubles and return the wanted feature , such as this one for the MeanAbsoluteValue : Since each of the features only ha...
Declare static classes so that they can be stored within List
C_sharp : sorry if this sounds noobish.I 'm trying to make a Quiz game on Unity by using C # and a database in SQL Server.In this part , i 'm trying to show the highest score so , i did a code to select the max in database : Then , i try to print the data in a UI text in this script : And it gives me this error : Index...
IndexOutOfRangeException while trying to select on database by C #
C_sharp : The main reason I 'm using the BST is to get the Majority Element , being the Value > Array.Length / 2.So , if we have an array of 5 elements , there must be a minimum of at least 3 to be considered the majority.Now the problem I am facing at the moment is that the Majority Element is being chosen for whichev...
C # Binary Search Tree giving Incorrect Majority Element
C_sharp : Can I use type parameter as implementing specific interface at Runtime without Reflection ? The following pseudocode is what I want to do . <code> void Run1 < T > ( ) { // ... if ( typeof ( IEnumerable ) .IsAssignableFrom ( typeof ( T ) ) { Run2 < T implementing IEnumerable > ( ) ; // < - use T as implementin...
Is there a way to cast type parameter ?
C_sharp : Why does the getter Val happen to simulate volatility for the field val ? I 'm assuming that leveraging a method call is not a reliable way to keep the variable volatile . ( To try it out , build for release and execute directly without the debugger . ) <code> class Program { private int val = 0 ; public int ...
Why does a method call flush the nonvolatile variable 's value to the main thread ?
C_sharp : I have a nested List as in the example : I want to merge all the lists having at least an element in common so that the output will be a List < List < int > > with elements : Thank you <code> List < List < int > > myList = new List < List < int > > ( ) ; myList.Add ( new List < int > { 2 , 7 , 3 } ) ; myList....
Merge element of nested List in unique list c #
C_sharp : Given the following class : What rules are applied to select one of its two generic methods ? For example , in the following code : it ends up calling EnumHelper.GetStrings < List < MyEnum > > ( List < MyEnum > ) ( i.e . Overload 1 ) , even though it seems just as valid to call EnumHelper.GetStrings < MyEnum ...
Why does n't the C # compiler consider this generic type inference ambiguous ?
C_sharp : I have to create a method for selecting a firts property from collection with the specified type.I have created the method like this ( I have removed some parts for the brevity ) : And I can call this method as : Everything works fine.But , I do n't want to set first argument type as Person , because compiler...
Set only second argument type in generic method
C_sharp : I 'm attempting to make a namespace for the first time while learning programming . I am hoping there is a way around the problem I 've run into that is n't particularly messy , but essentially I have a class object that keeps two dictionaries of two nested class objects . I need to be able to pass the Dictio...
Getting the type of another nested class from the same `` parent '' class
C_sharp : When there is no new ( ) constraint , I understand how it would work . The JIT Compiler sees T and if it 's a reference type makes uses the object versions of the code , and specializes for each value type case.How does it work if you have a new T ( ) in there ? Where does it look for ? <code> public T Foo < ...
C # - How do generics with the new ( ) constraint get machine code generated ?
C_sharp : I got a struct with the following fieldsWhen I initialise it and check the memory size , I get size as 8.However , when I change the order as below and execute it , I get the size as 12.Ideally , it should be 7 bytes . However , from this link msdn I can understand that overhead allocation do happens . Howeve...
Why the order of properties inside the Struct changes the size of instance ?
C_sharp : I 'm using NLog like thisBut I want to see the exception when debugging . So I tried : Is there a neater way of doing that ? <code> try { // ... some code } catch ( AException ex ) { logger.ErrorException ( ex.Message , ex ) ; } # if ! DEBUG try { # endif // ... some code # if ! DEBUG } catch ( AException ex ...
How to view exceptions when debugging ?
C_sharp : I 've made an app that can access and control Onvif cameras which it does well enough . However this is my first time making any app that uses web requests like this ( or at all ) so I assume I 'm probably using quite basic techniques.The part of code I 'm curious about is this : The code works fine , however...
Ways of speeding up WebRequests ?
C_sharp : Consider the following organization of classes : Since both the restaurants serve completely different sets of dishes , what will be the correct way ( design-wise ) to represent the type of dish in the interface ? Will it be a good design decision to define an Enum listing all the dishes -- Italian and Chines...
Should the interface define implementation specific enum values ?
C_sharp : I have a string which is 900-1000 characters long.the pattern string follows is `` Number : something , somestringNumber : something , somestring '' and so on example string : `` 23 : value , ordernew14 : valueagain , orderagain '' the requirement is whenever it crosses more than 1000 characters , I have to r...
Trim String value with particular pattern in C # .NET
C_sharp : I have a custom Matrix class that I would like to implement a custom object initializer similar to what a double [ , ] can use but can not seem to figure out how to implement it . Ideally I would like to have it look like thisas of now I have a regular constructor with a signature of that accepts a call like ...
How to implement a clean Custom Object Initializer for a Matrix class
C_sharp : What I want to do is have a method that takes a generic type as a parameter with a constraint . However , the constraint 's type also has a second generic type , but I want the method to work regardless of what the second typing is : Specifically , I 'm trying to have my EventManager class receive any kind of...
Generic methods with constraints that are generic
C_sharp : I 'm a substantial way through developing a sizeable WPF application that will control a sophisticated piece of hardware via serial comms . At the very bottom of the application `` stack '' I have a serial comms tier ( utilising the .Net 'SerialPort ' class ) . Reading and writing to the h/w device is a funda...
Should I use async `` all the way '' for my GUI app ?
C_sharp : If I have a generic function that returns a T or some default value I want to use the ? ? operatorThis fails with the message Operator ' ? ? ' can not be applied to operands of type 'T ' and 'T ' I assume this is because T might not be nullable . But I would also assume that the ? ? operator above should do t...
Why ca n't the ? ? -operator be applied to generic types , but a null-check can be applied ?
C_sharp : I am trying to pass a view model with complex types to my controller . I have researched everything I can top to bottom over this subject and I am still confused . The Problem : When I click my submit button , the view model is passed in but the List of MacroInfo property is null.UpdateIndexViewModelMacroInfo...
View model with complex type is null when passed to controller
C_sharp : How could be defined a code that store 'this ' during class finalization ? How the garbage collector should behave ( if defined somewhere ) ? In my mind the GC should finalize multiple times the class instance , and the following test application shall print `` 66 '' , but the finalizer is executed only once ...
Store 'this ' at finalization
C_sharp : I have the following code : It gives me this output : How can I ensure that some local variables will be passed to the BeginInvoke method as expected ? Thanks in advance . <code> string message ; while ( balloonMessages.TryDequeue ( out message ) ) { Console.WriteLine ( `` Outside : { 0 } '' , message ) ; Beg...
How to ensure the correct state of local variables when using BeginInvoke method
C_sharp : I was refactoring some the other day , I bumped into something like that : and ReSharper suggested to refactor it as : I am a bit skeptical , actually I am not sure when the implicit Dispose call will happen with the second version.How can I know ? <code> public async Task < Result > Handle ( CancelInitiatedC...
Refactoring : using statement without scope , when does the implicit ` Dispose ` call happen ?
C_sharp : I 'm doing some reaserch on CIL optimizing techniques . I 've created this simple code : When I watch this code in disassembly window , I see something like : I understand that it put 10 into ecx , then used 63A96648 as a pointer to WriteLine ( ) function , but I 'm not sure why does it use the ecx register ....
Why does Console.WriteLine ( ) use ecx register , event though eax and ebx are free ?
C_sharp : I got three classes ( classA , classB and classC ) that inherit from an interface 'IFoo ' ; if use this or it works just fine but other combinations wo n't even compile : orIt seems to me that in some cases the compiler implicitly unboxes the child classes to their IFoo interface but in some other cases do n'...
How null-coalsescing operator works
C_sharp : I have an OSS project on GitHub being built against .NET 4.5 on AppVeyor CI with Visual Studio 2017 ( not the preview stuff , just 2017 ) .The solution builds a COM add-in that extends a famously dreaded legacy Win32 IDE , and we 've established that the earliest Windows version we need to run on , is Vista (...
Can I have an analyzer on a .net 4.5 project ?
C_sharp : In all examples I can find as well as the automatically generated code i Visual Studio , events are set using the following code : But I can also write it visually cleaner by omitting the constructor wrapper : Which also compile fine.What is the difference between these two ? And why is the first one mostly u...
What the purpose/difference in using an event-type constructor
C_sharp : I was running through some code the other day and found this line which I thought was peculiar.I ca n't understand why they are multiplying by int 20 , and then dividing by float 20.0My initial suspicion is that it had something to do with either rounding or precision , but I could n't find the answer on here...
Is there a reason for mulitplying by an integer ' x ' , then dividing by that same ' x ' as a double ?
C_sharp : How do I group `` adjacent '' Sites : Given data : I want result : I tried using GroupBy with a custom comparer function checking routeIds match and first site 's end milepost is equal to the next sites start milepost . My HashKey function just checks out routeId so all sites within a route will get binned to...
How to use IEnumerable.GroupBy comparing multiple properties between elements ?
C_sharp : Before you rush to think about the ? ? null coalescing operator : The problem here is when whether myParent or objProperty are null , then it will throw an exception before even reaching the evaluation of strProperty.To avoid the following extra null checkings : I generally use something like this : So if the...
1 linear , beauty and clean way to assign value if null in C # ?
C_sharp : Is there a difference here ? andThe second method does n't seem to work for me but I 've seen it used when Google-ing 'how to remove an event handler ' . Edit : Actually neither are working for me , even so should either work interchangeably ? Update : The reason these did n't appear to work for me is because...
Is there a difference between these 2 ways of removing an event handler ?
C_sharp : My application has InstrumentFactory - the only place where I create Instrument instance . Each instrument instance contains several fields , such as Ticker=MSFT and GateId=1 and also unique Id =1.And now I realized that I almost never need Instrument instance . In 90 % of cases I just need Id . For example n...
When I need some item , should I just use its `` int id '' instead ?
C_sharp : I was testing the effects of calling a virtual member in a constructor , and discovered that when calling that member the resulting exception was wrapped within a TargetInvocationException.According to the docs this is : The exception that is thrown by methods invoked through reflectionHowever I 'm unaware of...
Are virtual members called via reflection ( in normal circumstances ) ?
C_sharp : I 'm am working on having a screen that allows the user to change the order of items , and when the user clicks on the `` Save '' button my javascript will look at the order of < li > items , and in the order it finds them it will form an array with an id value and send it back to my application . I expect th...
Can I assume that the order I send values over POST will be model bound to an array in the same order in Asp.net MVC ?
C_sharp : On my server I have a route that generates a pdf for a user . When the generation takes longer than a specified amount of time , the route is supposed to return an accepted status code and send a email to the user when the processing is finished . The issue I am having is that the Task.Delay is not being resp...
C # Async ApiController route issue resolving Task.WhenAny with a Task.Delay
C_sharp : I have EditorFor in my View.Like this Also I Action in controller that find all NULL in table from database and update it with some value , here is codeIn Index View I tap button that goes to Update Action and launch itHere is codeBut here is update with static value , and I want to recieve value from VIew . ...
Pass value from EditorFor to method
C_sharp : Is it possible to get the name of another method in the same class but without using a manually written string ? You may ask why : well the reason is that I must invoke the method later on like this Invoke ( `` otherMethod '' ) , however I do n't want to hardcode this string myself as I ca n't refactor it any...
How to get the methodname from a known method ?
C_sharp : I have a problem with my query using dapper , whether someone imagine to help me and say where I 'm doing the wrong , is currently showing me an error at the date when I put a breik point , how to correct it properly ? thank you all for helpthis is my current codeand this is the result with which I get an err...
Selection using dapper
C_sharp : I have a hierarchy of TrendProviders which are used to provide a series of datapoints ( trends ) from different sources.I have started with the generic interface : TrendResult is a result class with the obtained trend data and operation status code : TrendResultCode is as follows : There are also two types ( ...
c # polymorphism + generics design - advice needed
C_sharp : Imagine I have a list of items : Now from somewhere a server tells my application that element B was removed , yet it only provides the entire new list , not the exact change details.Since WinRT ListViews automatically animate addition , removal , and movement of items inside them , I would prefer not to refr...
Replicating changes in a list
C_sharp : I 'm struggling with multithreading in C # ( which I 'm learning just for fun ) and realise I probably do n't understand what a thread is ! When I run the code below , I was expecting to get something like the following output . ( possibly in a different order ) However , I 'm getting something likeI had assu...
ThreadLocal < T > - What is a thread ? ( C # )
C_sharp : I have ef classes like this : And want to make request like : Problem : Problem is that when I fetch for example 1000 products this partmake query for every row and its very slow.What I seen in debugger that for each product make query to fetch BannedIn , but should be already fetched cause I have IncludeWhat...
Linq request make a lot of queries to DB
C_sharp : Considering the next struct ... and the next matrix definitionswhich one of the matrices will use less memory space ? or are they equivalent ( byte per byte ) ? <code> struct Cell { int Value ; } var MatrixOfInts = new int [ 1000,1000 ] ; var MatrixOfCells = new Cell [ 1000,1000 ] ;
Is equivalent the memory used by an array of ints vs an array of structs having just one int ?
C_sharp : As input to another program I am using I need to input a delegate of the form : I want the function to be sent in to be F ( a , b ) =a+b*c+dwhere c and d are known constants known at runtime.So what I need is some method which takes the values c and d , and then gives me a function F ( a , b ) . What I think ...
Create a function which gives us another function
C_sharp : I am using an int array to hold a long list of integers . For each element of this array I want to check if it is 1 , if so do stuff relevant to 1 only , else if it is a 2 , do other stuff relevant to 2 , and so forth for each value stored in the array . I came up with the code below but it is n't working as ...
Cycling through contents of array issue
C_sharp : Why are exceptions always accepted as a return type ( thrown ) ? Valid example 1 : Invalid example ( obviously ) : Valid example 2 : I can see that my `` Invalid Example '' is 'throwing ' and not 'returning ' the Exception , however , my method does never return the type defined by the method . How come my co...
Why are exceptions always accepted as a return type ( when thrown ) ?
C_sharp : I 'm attempting to return an image from a server route , but I 'm getting one that is 0 bytes . I suspect it has something to do with how I 'm using the MemoryStream . Here 's my code : Through debugging I have verified that the PdfToImages method is working and that imageMemoryStream gets filled with data fr...
Not Receiving Data from Route C #
C_sharp : I need to generate all the substring of a given length , of a string.For example all the substrings of length 3 of `` abcdefg '' are : For this task I wrote this function : that I use like this : I wonder if it is possible to write the same function avoiding the variable result and using yield <code> abcbcdcd...
Generating all the substring of a given length using yield
C_sharp : We knows that TPL ( so PLINQ too ) does n't consume all cores if he think that task is easy and executes it on single core . But he does it even for a complicated task ! For example , here is code from article about Java parallelism : and results : you can see that multithreaded version executed ~19 times fas...
What heuristic uses TPL to determine when to use multiple cores
C_sharp : My C # application server.exe is critical to my business operations and ideally needs to run without interruption 24/7 . The code is rock solid but one thing that 's out of my control is the poor quality of inbound data feeds that are generated by third parties . I 'll occasionally receive data feeds that con...
How can I get a portion of my C # app to load dynamically without app restart ?
C_sharp : In my C # code , I need to evaluate two non-null variables . I worked out a set of if-else if statements , but in my mind it looks ugly and a little bit too sloppy , even if it is correct.I looked in the MSDN Library and saw only examples for selection based on a single variable.Is there a cleaner and more co...
Is there an efficient way to do a selection statement with two variables ?
C_sharp : I have some context in code to be switched depending on whether it is running under test or release.Say in my product coding : The way I am thinking about is make a TestFlag class : This seems verbose if I have many place to do that . Is there any good pattern to do it ? <code> PublishRequest ( ) ; // the rea...
Is there any good way to switch different context between Unit Test and Release . in C #