text stringlengths 46 37.3k | title stringlengths 12 162 |
|---|---|
C_sharp : I have many hours thinking how i can solve , this is my funtion : This function split a string in parts of 36 characters then add the resultant characters with spaces for make a centered text : For example : Result : Line1 and Line2 are correct but i dont need the Line3 , how i can prevent to print this unnec... | Center and Split string with maxchar |
C_sharp : So Inversion Of Control is a vague description , so Dependency Injection became the new definition . This is a very , very powerful solution and is quite possibly just as confusing to someone whom has never encountered it.So in my quest to not be a deer in headlights , I read up . I found several terrific boo... | The Five W 's of DI , IoC because it is making my brain explode |
C_sharp : The following returns trueso doesThe RegEx is in SingleLine mode by default , so $ should not match \n . \n is not an allowed character.This is to match a single ASCII PascalCaseWord ( yes , it will match a trailing Cap ) Does n't work with any combinations of RegexOptions.Multiline | RegexOptions.SinglelineW... | C # System.RegEx matches LF when it should not |
C_sharp : Really simple to replicate , the output is bizarre ; Expected output is `` bbb bbb '' Actual output is `` aaa bbb '' Has anyone got any MSDN explanation of this behaviour ? I could n't find any . <code> ( ( a ) new b ( ) ) .test ( ) ; new b ( ) .test ( ) ; public class a { public virtual void test ( string bo... | Overriding default parameters in C # |
C_sharp : I have the following scenario/requirement : I have two tasks , task A and task B , which both return the same type of data.If task A , upon completion , has data in its result , I need to return the result of Task A - otherwise I return the result of task B.I 'm trying to performance optimize this for paralle... | C # async/await - multiple tasks with one preferred |
C_sharp : I have a class that expects an IWorkspace to be created : and a derived class Derived . In this derived class I have a copy-constrcutor that should create an instance of Derived based on an instance of MyClass . The above won´t compile with following error : Can not access protected member MyClass.workspace '... | Create a constructor that does not exist in base class |
C_sharp : In my program , I ran into a problem writing a small number to a context.Response that is then being read by a jQuery ajax response.returns [ object XMLDocument ] However , returns 0.00 as expected.Using `` n '' is perfectly fine for my program , but why did `` # . # '' return with an XMLDocument ? <code> val... | Why does n't # . # work for very small numbers ? |
C_sharp : I feel like I 'm stuck between several bad solutions here and need some advice on how to minimize future agony . We are using Massive ORM , which in its constructor has these lines : The important part for me here is that it reads the connection strings from ConfigurationManager . We are trying to centralize ... | Least-bad way to change constructor behaviour |
C_sharp : Is there any essential difference between this code : and this ? Or does the first invoke the method on the current thread while the second invokes it on a new thread ? <code> ThreadStart starter = new ThreadStart ( SomeMethod ) ; starter.Invoke ( ) ; ThreadStart starter = new ThreadStart ( SomeMethod ) ; Thr... | .NET threading question |
C_sharp : I 've got an Application which consists of 2 parts at the momentA Viewer that receives data from a database using EFA Service that manipulates data from the database at runtime.The logic behind the scenes includes some projects such as repositories - data access is realized with a unit of work . The Viewer it... | How to ... Display Data from Database |
C_sharp : doing a little experimenting to find out how things work . I have the following code ... I 'm wondering why MethodTest receives the int 20 almost always ( unless I 'm stepping through in debugger ) .Obviously there 's something missing in my understanding as I assumed that when ' i ' is passed it would be par... | Private variables in .net 4.0 tasks |
C_sharp : Update : check out the example at the bottomI need to message between classes . The publisher will loop indefinitely , call some method to get data , and then pass the result of that call into OnNext . There can be many subscribers , but there should only ever be one IObservable , and one long-running task . ... | How to Separate IObservable and IObserver |
C_sharp : When you have some property that 's like : then compile and later change it to : it seems like the compiled code is different between the two assemblies , which I could see using the Reflector.Why does the compiler differentiates between the two code ? Is n't it only necessary to see if there is any ambiguous... | Why does the C # compiler differentiates between these 2 cases ? |
C_sharp : Straight to the point : I get a very related question which actually deals on why does i.ToString ( ) work fine.Edit : Just found out this corner case has been the most voted one in this SO thread ! <code> int ? i = null ; i.ToString ( ) ; //happyi.GetType ( ) ; //not happy | Why does some methods work while some do not on null values of nullable structs ? |
C_sharp : I wrote a tool that generates a C # source file containing the results of a processor intensive computation ( precomputing the result speeds up the startup time of my application by roughly 15 minutes ) . It is a byte [ ] that looks sorta like this : I 'm wondering though , are there hidden costs for hardcodi... | Are there hidden expenses hardcoding data as code in C # ? |
C_sharp : I need to calculate distances between every pair of points in an array and only want to do that once per pair . Is what I 've come up with efficient enough or is there a better way ? Here 's an example , along with a visual to explain what I 'm trying to obtain : e.g. , first get segments A-B , A-C , A-D ; th... | What is the most efficient way to avoid duplicate operations in a C # array ? |
C_sharp : Take the following code : The identifier foo has two types : IFoo - This is the type the compiler will enforce . I will only be able to call methods that are part of the IFoo contract , otherwise I 'll get a compiler error.FooImplementation - This is the type as known by the runtime . I can downcast foo to a ... | What is the proper terminology for each type of an identifier ? |
C_sharp : I have a table that stores the history of changes on a product and want to get a list of records that have a change in Col1 or Col2 or Col3 but not show me records that do not have a change in any of these three columns .Here 's an example done in SQL . How do you do with Linq ? Create temporary table for tes... | Linq Filter row differences in historical |
C_sharp : We know that these two addition statements are equivalent and compile to the same IL code : However , when there is an explicit cast required I have noticed something strange : It is obvious why the second statement requires an explicit cast because the result of the addition is an integer . But the weird thi... | Why is x = x + 100 treated differently than x += 100 that compiles to the same IL ? |
C_sharp : I have a bit of a hard time putting this just in words , so I 'll use some code to help explain myself and my problem.So imagine I have two classes ClassA and ClassB : as you can see ClassB contains ClassA , but I have another class for it ClassAOwned because I want ClassB to own ClassA ( flatten its columns ... | How to set class property 's value to be set to generated id value of another class on insertion to database ? |
C_sharp : Q1 Why do new classes from .NET implement interfaces only partially ? Q2 Shall I do the same in my code ? I asked this question here , so I thought , okay that was long time ago , you can have different usage etc etc , and now such implementation is supported only for consistency reasons . But new classes als... | Why do core types implement interfaces only partly ? |
C_sharp : The given codeemits the following warning : If I remove .Select ( ) clause it disappears.But it 's not clear to me what exactly I need to .Ensure so that the cccheck was satisfied . <code> static public int Q ( ) { return Enumerable.Range ( 0 , 100 ) .Select ( i = > i ) .First ( ) ; } warning : CodeContracts ... | Contract that ensures the IEnumerable is not empty |
C_sharp : I have a theorical/pratical question about how inheritance works in C # .Let 's say that I have to model some autos , so I have a few common methods that all the autos must implement and a pilot should know . In code-words this should be an Interface : Now , all kind of car should have some common technical i... | About C # and Inheritance |
C_sharp : I could n't find any information on this through professor Google , so here I am . Take the given path name and paste it into Windows Explorer . I stumbled across this after discovering bug in my code that generated the paths with an extra ' . ' in the path name before a directory \ separator ... In code , .N... | Strange behavior from .NET regarding file paths |
C_sharp : I am trying to read the System Event Logs in C # .NET 3.5 with the following method EventLog.GetEventLogs . This seems to be working perfectly for all kinds of Event Logs that I want to take a look at . There is but one exception : Microsoft-Windows-Kernel-Power Event Logs which can be read but produces the f... | The description for Event ID ' X ' in Source 'Microsoft-Windows-Kernel-Power ' can not be found |
C_sharp : I 'm facing a general question where I ca n't find a good example to try-it-for-myself . Google is n't a help neither.Imagine a structure like this : What if the server is slow and takes a while to accept the mail . Is it possible that the SmtpClient is disposed before the operation is done ? Will it be cance... | Using-statement with async call | Cancel operation ? |
C_sharp : I have an array of Vehicles in C # and some vehicles are Cars and others are SUVs . I am wondering what is the best way to fetch car with lowest weight . If no car is found in the array then find SUV with lowest weight.Below is code segment I have using LINQ . I am wondering if there is better way to fetch th... | Selecting first element of a group from LINQ search results |
C_sharp : Most , if not all , examples of Dapper in .NET I 've seen use a structure like this : If you have a Web API , is it wise to make a new connection every time a request is made to the server ? Or would it be a better pattern to abstract the connection into another class and inject it into each controller so the... | Reusing database connection with Dapper in .NET Web API |
C_sharp : Suppose you have 2 classes like so : Now imagine you have an instance of each class and you want to copy the values from a into b . Is there something like MemberwiseClone that would copy the values where the property names match ( and of course is fault tolerant -- one has a get , and the other a set , etc .... | Is there anything built into .NET/C # for copying values between objects ? |
C_sharp : I have an interface IKey which I want to have a method which will return the key as a string . We looked at having a method like this : which would return the string representation , but would have liked to be able to declare ToString ( ) again in the interface to force implementers to implement it , but it d... | Is taking advantage of optional parameter edge cases to force implementations of ToString via an interface abuse of the language ? |
C_sharp : i have this classand i have a manager that gets several lists of ConnectionResult and count each value greater then a specific number determined by configuration . my implementation is so : but i want to make it better , so i started to write it in linq and i got tobut this gives me an error of Can not implic... | Need better way to sum up data |
C_sharp : For example , if I had two lists , I 'd do : Or if I had three , I 'd dobut if I do n't know at compile time how many lists are in the lists collection , how can I easily iterate over every permutation ? A C # solution is ideal , but a solution in any language that demonstrates a suitable algorithm would be h... | How do you iterate over an arbitrary number of lists , including every permutation ? |
C_sharp : Hello everyone : ) Here 's the situation : I have a baddy prefab which has two collider components : a simple CapsuleCollider2D used for physics , and a trigger PolygonCollider2D used only for mouse point collisions.The PolygonCollider2D is updated through an attached script ( Baddy.cs ) only when needed usin... | Prefab Collider2D not Recognized as Raycast Collider |
C_sharp : Consider this code : In above code s is string but b is false.actually s as string , Why i get this result ? Why compiler has this behavior ? <code> class Program { static void Main ( string [ ] args ) { string s = null ; bool b = s is string ; Console.WriteLine ( b ) ; } } | Why null string is not a string object |
C_sharp : I 'm wondering if there is a better way to approach this problem . The objective is to reuse code.Let ’ s say that I have a Linq-To-SQL datacontext and I 've written a `` repository style '' class that wraps up a lot of the methods I need and exposes IQueryables . ( so far , no problem ) .Now , I 'm building ... | Is there anything wrong with having a few private methods exposing IQueryable < T > and all public methods exposing IEnumerable < T > ? |
C_sharp : I have an Item class . I have around 10-20 derivatives of it each containing different types of data . Now when it comes to rendering different types of Item , I 'm forced to use likes of : Unfortunately @ Html.DisplayFor ( ) does not work in this case because the Model is type of Item , DisplayTemplates\Item... | How to render derived types of a class differently ? |
C_sharp : So I have an integer , e.g . 1234567890 , and a given set of numbers , e.g . { 4 , 7 , 18 , 32 , 57 , 68 } The question is whether 1234567890 can be made up from the numbers given ( you can use a number more than once , and you do n't have to use all of them ) . In the case above , one solution is:38580246 * ... | How can I determine if a certain number can be made up from a set of numbers ? |
C_sharp : Say I have an array that is stored in 0° rotation : And I want it returned in a good approximation if I pass , for example 30° as parameter , it would be something like:45° would beI am aware of the solutions posted for 90° rotations . But I do n't think that will help me here ? I do n't have any examplecode ... | How can I rotate a 2d array by LESS than 90° , to the best approximation ? |
C_sharp : When I run this query in linqpad : It returns a record that matches.When I try running the same query in visual studio it does not return any matching records . This is the code I am using : Can anyone see why this it works in linqpad but does not work in visual studio ? <code> Customer.Where ( c = > ( c.Cust... | linq query for varchar field not returning any results |
C_sharp : The following snippet is taken from an example of ComboBox : :DrawItem implementation on this MSDN page : I question this part : new SolidBrush ( animalColor ) Since this is neither deliberately given a Dispose nor is it wrapped in a using , I assume this is also an example of poor form , since the SolidBrush... | Is an object creating using an `` inline '' new statement automatically disposed ? |
C_sharp : Imagine that I have a visits index that contains documents of type 'visit ' that look like the following : The following function will return a histogram which returns buckets of visits for each day in the given range according to the given time zone.Now imagine that I changed things up a bit . Imagine that I... | How can I reshape my data before I turn it into a histogram ? |
C_sharp : I 'm working on a rehosted workflow designer using WF 4 , my application which uses this designer control is a multi-language application that loads 2 or more language specific resource dlls . if I have two satellite assemblies for one language such as `` en '' and `` en-US '' , designer throws an exception l... | WF 4 error with language specific resource dlls |
C_sharp : I always see singletons implemented like this : Is there 's something wrong with implementing it like this : ? It gets lazy initialized on the very same moment as in the first implementation so I wonder why this is n't a popular solution ? It should be also faster because there 's no need for a condition , lo... | Singleton shortened implementation |
C_sharp : I 'm creating an ASP.net website which handles thousands of requests and it all stems from one main object that they all share to read it . I 'm trying to wrap my head around these different types of locks.Some common questions i have for each.What is the scope of each lock Application , Session , ObjectWhen ... | understanding Locking help ? |
C_sharp : Question : Is this code look alright ? I understand that to be a key in the Map , Foo needs to override equals and hashcode methods - either override both or none.I was wondering what about List of objects as keys ? What does equality means when it comes to List ? is the map defined above safe from `` object-... | Can I use List of objects as Dictionary Keys ? |
C_sharp : I want to take a List of strings with around 12 objects and split it into two List of strings but completely randomise it.Example of List : List 1 : Apply some logic here ... Result gives me two lists : List 1 : List 2 : I 'm a newbie to C # MVC , so I 've found some answers on Stack but none have been able t... | Create two random lists from one list |
C_sharp : Back in the old days of C , one could use array subscripting to address storage in very useful ways . For example , one could declare an array as such . This array represents an EEPROM image with 8 bit words.And later refer to that array as if it were really multi-dimensional storage I 'm sure I have the synt... | Question about array subscripting in C # |
C_sharp : I have a binding : and this C # code : Note that GridLength is a structure : https : //docs.microsoft.com/en-us/dotnet/api/xamarin.forms.gridlength ? view=xamarin-formsDoes anyone know how I can bind to the value marked with ? ? ? For more explanation here 's what I am trying to do : I would like to be able t... | How can I bind to a Grid ColumnDefinition Width in C # |
C_sharp : I assume the following sample gives a best practice that we should follow when we implement the IEnumerable interface.https : //docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerator.movenextHere is the question : Why should we provide two version of Current method ? When the version ONE ( object ... | C # - Why implement two version of Current when realizing IEnumerable Interface ? |
C_sharp : Based on random Internet comments , I 've always believed that the C # compiler does simple optimizations to the IL ( removing always-true if-statements , simple inlining , etc ) , then later the JIT performs the real , complex optimizations.As just one example , on the documentation for the /optimize compile... | Does the C # language compiler perform any actual optimizations on its own ? |
C_sharp : Word seems to use a different apostrophe character than Visual Studio and it is causing problems with using Regex . I am trying to edit some Word documents in C # using OpenXML . I am basically replacing [ [ COMPANY ] ] with a company name . This has worked pretty smoothly until I have reached my corner case ... | Issue with find and replace apostrophe ( ' ) in a Word Docx using OpenXML and Regex |
C_sharp : I 'm experimenting with locks that do n't require atomic instructions . Peterson 's algorithm seemed like the simplest place to start . However , with enough iterations , something goes wrong.Code : When I run this , I consistently get < 2,000,000 . What 's going on ? <code> public class Program { private sta... | Why does Peterson 's lock fail in this test ? |
C_sharp : I mostly understand deferred execution , but I have a question about a particular case : Given a code fragment such ashow many times is the query resultsOfInterest executed ? Once when setting up the foreach loop , or once for every element ' x ' ? Would it be more efficient with ? TIA <code> var resultsOfInt... | Linq deferred operations |
C_sharp : I want to create a library that will create objects using a user-defined function and modify them using another user-defined function . I have an OCaml background and see a fairly straightforward way to implement it : The problem is that I want that library to be easy to call from C # : having functions as ar... | OO alternative to polymorphism in F # when calling F # from C # |
C_sharp : I was wondering why ReSharper does warn me , when I 'm trying to convert a char to a string without giving a specific culture info.Is there any case , where it could be converted differently on two systems ? Example : The following ReSharper warning will pop up by default : Specify a culture in string convers... | Why does ReSharper warn at Char.ToString ( ) when not specifying CultureInfo explicitly ? |
C_sharp : I can refactor this code ( popular as/null check pattern ) ..into a nice `` is '' type pattern expression : ..which is cool ... I think ... Is it ? But now I am also thinking to refactor..into : Note : there is no as and SomeMethod ( ) already returns MyType . It looks like ( pseudocode ) if ( A is A ) and ma... | The `` is '' type pattern expression for null check |
C_sharp : I 'm curious if it is possible to determine whether or not an Assembly has referenced a particular class or not . I 'm currently using Reflection to load Assemblies and then I determine what Assemblies are being referenced from within the assembly I am loading : Now that I know what Assemblies are referenced ... | Determining if a class is referenced C # |
C_sharp : I am developing a program which uses visual styles . The Main method looks like this : The program also works as a plugin of another application and it is started , in this case , via COM . The problem is that the calling application ( the COM client ) does n't call EnableVisualStyles and it is out of my cont... | Visual styles do n't work on an in-process COM server |
C_sharp : In Visual Studio 2013 Ultimate , Microsoft introduced a feature named CodeLens . A handy feature which ( among others ) has the ability to count the number of times a method is referenced in your project . At the moment we 're using VS2015 Pro and I 'm working in a big solution with multiple projects in it . ... | Prevent Visual Studio from counting references of certain methods |
C_sharp : I have some code that I have no control of . This code accepts an object parameter and attempts to cast it to a type known at compile time like this : Is it possible in C # to design a custom class MyClass ( not derived from KnownType ) that can be passed as parameter to the above code and be converted to Kno... | C # dynamic conversion through cast operator |
C_sharp : Consider the following scenario of services and components in a sample C # console application Let 's imagine to do the following registrations inside the composition root : This kind of scenario works fine and I did so several times.What if , for some reason , I would like to inject inside the constructor of... | Castle Windsor : inject IEnumerable < IService > using only a subset of registered components for IService |
C_sharp : I was curious on the overhead of a large structure vs. a small structure in using operators + and * for math . So I made two struct , one Small with 1 double field ( 8 bytes ) and one Big with 10 doubles ( 80 bytes ) . In all my operations I only manipulate one field called x.First I defined in both structure... | Peculiar result relating to struct size and performance |
C_sharp : I 'm trying to check if an enum option is contained in the available options.Its a little bit difficult for me to explain it in english.Here 's the code : I 'm trying to check if the me varliable is contained in the available variable.I know it can be done because it 's used with the RegexOptions too . <code>... | c # check enum is contained in options |
C_sharp : I 'm in need to create a method which allows me to populate a List < string > with the values of the constants that are defined in the own class.To give you a quick example of the numerous ( 20 in total ) constants that are defined in the class : As you can see , the name of the constant equals the value of i... | Method to populate a List < string > with class constant values . C # |
C_sharp : I am trying to dynamically get the schema of one of my views in SQLite using C # . I am using this code : Its working perfectly for all my tables and views except for one view . For some reason , the data type for the field called SaleAmount is coming up blank . There is nothing in the row [ `` DATA_TYPE '' ]... | ADO.Net reporting empty data type in SQLite |
C_sharp : I was thinking about GUIDs recently , which led me to try this code : You can see that all of the bytes are there , but half of them are in the wrong order when I use BitConverter.ToString . Why is this ? <code> Guid guid = Guid.NewGuid ( ) ; Console.WriteLine ( guid.ToString ( ) ) ; //prints 6d1dc8c8-cd83-45... | Why are these two strings not equal ? |
C_sharp : In my quest to the primes , I 've already asked this question : Ca n't create huge arrays which lead me to create my own class of fake arrays based on a dictionary of arrays ... : private Dictionary < int , Array > arrays = new Dictionary < int , Array > ( ) ; I can know create fake arrays of a lot of bool ( ... | Create huge dictionary |
C_sharp : I have the following input text : I would like to parse the values with the @ name=value syntax as name/value pairs . Parsing the previous string should result in the following named captures : I tried the following regex , which got me almost there : The primary issue is that it captures the opening quote in... | Parsing text between quotes with .NET regular expressions |
C_sharp : I 'd like to do something like this : Note : I 'm running tasks on the thread pool , so there is no async context.I 'd like to be able to tell the difference between an exception thrown immediately , and I 'm still on the calling thread ( e.g . parameter is invalid causing the function to abort ) , and an exc... | async await exception catching - which thread am I on ? |
C_sharp : Is it sufficient to compare the ManagedThreadId at the time an object is created and at the time a method is called to verify that it is n't being used in a multithreading scenario ? My intuition is often wrong about threading , so I wanted to check to see if there are edge cases I should be keeping in mind .... | How do I detect multi-threaded use ? |
C_sharp : I ca n't quite explain to myself in clear terms why a Task spawn by a Timer works just fine but a Timer spawn by a Task does NOT.All relevant code is included below so you can easily reproduce it.Form.cs : ProcessDelayList.cs : ProcessDelay.cs : <code> private void Form1_Load ( object sender , EventArgs e ) {... | Timer Spawn By Task And Task Spawn By Timer |
C_sharp : I have the following line of code , with works in VS 2015 and .Net 4.0 , but I am getting an error in VS 2013.Why it works in a different way ? <code> StringBuilder s = new StringBuilder ( `` test '' ) { [ 0 ] = 'T ' } ; | StringBuilder initializer works one way in VS2015 but another in VS2013 |
C_sharp : Given this Java code , this outputs 0 and 4 : And with this identical C # code , this outputs 4 and 4using System ; Though I figure out that the output should be 4 and 4 on Java , but the answer is actually 0 and 4 on Java . Then I tried it in C # , the answer is 4 and 4What gives ? Java rationale is , during... | Java constructor is not so intuitive . Or perhaps it 's not Java , it 's C # that is not intuitive |
C_sharp : That 's the best way I could think to ask the question , the detail is below . It 's taken me an hour just to figure out how to ask the question ! Let 's say that I have 5 ( or more ) types of text files - they are generated by a scientific instrument and each has certain results . Let 's call these `` types ... | How do I make a new list of strings from another list based on certain criteria ? |
C_sharp : I have an array of custom objects named AnalysisResult . The array can contain hundreds of thousands of objects ; and , occasionally I need only the Distinct ( ) elements of that array . So , I wrote a item comparer class called AnalysisResultDistinctItemComparer and do my call like this : My problem here is ... | How to report progress on a long call to .Distinct ( ) in C # |
C_sharp : Edit # 2 : config.FilePath is showing that it 's looking at a different file than what I 'm expecting : `` C : \Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config '' . I was expecting it to use the web.config in my project . Need to figure out why that 's happening.I have a method in my web API wh... | Reading AuthorizationSection from web.config provides incorrect values |
C_sharp : I have written a piece of optimized code that contains special cases for null and empty strings . I am now trying to write a unit test for this code . In order to do that , I need two empty ( zero-length ) string objects that are different objects . Like this : It turns out that most .NET Framework APIs strin... | How to manufacture an empty string in .NET ? |
C_sharp : I 'm not a C # guy I 'm more an Objective-C guy but lately I 've seen a lot of implementations of : Instead of : One of the examples of this is the MVVM Light Framework , there the developer implements the data service contract ( and implementation ) using the first approach , so my question is : Why this ? I... | Action < T > vs Standard Return |
C_sharp : I have a text file which has lines of data separated by newlines . What I 'm trying to do is count the number of lines in the file , excluding the ones that are only a newline . I 'm trying to use a regular expression to look at each line as it is read , and if it starts with a newline character not include i... | Match only a newline character |
C_sharp : Why C # compiler does not allow you to compile this : but does allow you to compile : where MyStruct is defined as : Update : in the firsts case the error is : Error 1 Use of unassigned local variable ' a ' <code> int a ; Console.WriteLine ( a ) ; MyStruct a ; Console.WriteLine ( a ) ; struct MyStruct { } | Differences between user created structs and framework structs in .NET |
C_sharp : I am a reasonably experiences hobby programmer , and I have good familiarity with C++ , D , Java , C # and others.With the exception of Go , almost every language requires me to explicitly state that I am implementing an interface . This is borderline ridiculous , since we today have compilers for languages l... | What other languages support Go 's style of interfacing without explicit declaration ? |
C_sharp : I 'm attempting to add an error to the ModelState by using nameof : In the view , this has been tagged with a name of Foo.Bar . When I add a model state error , I have to key that error to a name , so I use nameof ( Foo.Bar ) - however this just gives me Bar , when I need Foo.Bar . Right now I can hardcode Fo... | using nameof ( ) to inspect class name with its parent for MVC validation |
C_sharp : I have some code that takes a value ( of type object ) and tries to cast it to an IEnumerable of ints and uints like so : When the value is initialized this way : both idList and uintList have values , but calling idList.ToList ( ) results in an ArrayTypeMismatchException . However , when the value is generat... | Why does casting a value as IEnumerable < T > behave differently based on how I initialized the value ? |
C_sharp : Let say I have The question is are there two iterations or just one.In other words , is that equivalent in performance to : <code> IEnumerable < int > list = new int [ ] { 1 , 2 , 3 } ; List < int > filtered = list.Select ( item = > item * 10 ) .Where ( item = > item < 20 ) .ToList ( ) ; IEnumerable < int > l... | Does Select followed by Where result in two iterations over the IEnumerable ? |
C_sharp : I want to make it so that if the value of subs is not `` '' then the ULs go before and after it and into the variable sL . If subs is `` '' then sL get the value `` '' But it does n't seem to work . Is my format correct ? <code> var sL = ( subs ! = `` '' ) ? `` < ul > '' + subs + `` < /ul > '' : `` '' ; | Confused about the ? operator in c # |
C_sharp : I have a base abstract class and its abstract type parameter as : Then I have number of children classes inherent from it : Now , I want to put a Dictionary to keep track of the databases and a method to return them using DatabaseItem type , something like this : Then it gave me `` 'T ' must be a non-abstract... | Handling classes inherent from abstract class and type parameter |
C_sharp : I have a list of numbers and I want to find closest four numbers to a search number.For example if the search number is 400000 and the list is : { 150000 , 250000 , 400000 , 550000 , 850000 , 300000 , 200000 ) , then the closest 4 numbers would be : Any help or suggestion would be appreciated . <code> { 30000... | C # linq list find closest numbers |
C_sharp : I have an API call using SmartyAddress , here is the result returned from the API call : Now I would like to use JSON to return this result especially the analysis component , and here is the code I tried to write , but it always gives me the error : can not deserialize the current json object into type 'syst... | API Call in C # using JSON |
C_sharp : If I have a routine that can throw an ArgumentException in two places , something like ... What ’ s the best way of determining in my calling procedure which of the two exceptions was thrown ? Or Am I doing this in the wrong fashion ? <code> if ( Var1 == null ) { throw new ArgumentException ( `` Var1 is null ... | Which of the two exceptions was called ? |
C_sharp : I 'll give a quick example of what I 'm familiar with implementing using C. The focus I think is on how the data can be used , not so much what I 'm doing with it in the example : ) So I 'm looking for advice on how similar data tables , or reference data , are implemented in C # . I 'm getting the hang of th... | Coming from a C background , what 's a good way to implement const reference data tables/structures in C # ? |
C_sharp : From what I can piece together : int SalesTeamId is a variable and person is being assigned to the variable . After that I 'm lost . Any guidance ? <code> int salesTeamId = person == null ? -1 : person.SalesTeam.Id ; | Could someone interpret this line of code ? |
C_sharp : The MessageBox.Show call below shows `` Inner '' . Is this a bug ? <code> private void Throw ( ) { Invoke ( new Action ( ( ) = > { throw new Exception ( `` Outer '' , new Exception ( `` Inner '' ) ) ; } ) ) ; } private void button1_Click ( object sender , EventArgs e ) { try { Throw ( ) ; } catch ( Exception ... | Control.Invoke unwraps the outer exception and propagates the inner exception instead |
C_sharp : I 'm seeing some strange behavior when using a nullable long switch statement in VS2015 Update 1 that I 'm not seeing in other Visual Studio releases where it runs as expected.This sample code produces the following output ( Aligned for readability ) : I 'm only observing this behavior with Nullable types . N... | Nullable Long switch statement not producing expected output in VS2015 |
C_sharp : What are the rules when resolving variable number of parameters passed by params ? Suppose , that I have the code : How is Method ( a , b , c ) resolved , if a is a IMyInterface ? Can I be sure , that C # will always try to select most matching overload ? <code> public void Method ( params object [ ] objects ... | Resolving params in C # |
C_sharp : In C # , the following method will not compile : The compiler errors : 'IsItTrue ( ) ' : not all code paths return a value , which makes perfect sense . But the following compile without any issue . Which looks wrong as no return statement at all . Why is it so ? Any help here ... , <code> public bool IsItTru... | Why compiler behaves differently with this code ? |
C_sharp : I 've built a method that returns me an instance of attribute if it is found on the property : In order to get instance , I have to invoke : And it works fine , I get exact instance of the attribute class.However , I do n't like that I have to use new NullableAttribute ( ) as parameter , I 'd like to have inv... | Inferring 2 out of 3 generic types |
C_sharp : I was just wondering if a simple static function using the ? : operator is inlined during just in time compilation . Here is an arbitrary example using the code.Which gives the following IL : Or would the simplier alternative be inlined ? Here is the IL for it : The ? : operator apparently generates a more co... | Are Methods using the ? : Operator Inlined during JIT compilation ? |
C_sharp : I need an accurate searching function whether in jquery or c # . If possible I want the searching as brilliant as google : - ) So here is c # code : Brief explanation : This searches all users in database that has complete information . It searches all users except the currently logged in user . And the resul... | How to create more accurate searching ? |
C_sharp : I 'm looking to understand a bit more about LINQ and use it a little more , so a little bit of self development work going here ... I have an object as follows : Now , given a list of players , I 'd like to select the ones that have formerly played for various selected clubs , I could do it easily by a couple... | Object population with LINQ |
C_sharp : I ca n't figure it out , where did I go wrong ? I got the following datetime string , and need to parse it to datetime : And I trying to parse it like this : When trying to do this it returns `` string was not recognized as a valid DateTime '' Any tip ? <code> string timestr = `` 1/20/2014 12:05:16 AM '' Date... | How can I parse this datetime string ? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.