text
stringlengths
46
37.3k
title
stringlengths
12
162
C_sharp : Basically I 'm doing is converting from Exception to GenericFaultException class ( The below code snippet uses C # as a language.See the below details I have created a faultExceptionObject using the below line of codeI have a Error handling layer which do not have any idea about ValidationFault class , only i...
Generic conversion
C_sharp : I am using windows forms.My C # application contains 100 user controls . I show/hide one of those 100 user controls at a time when I need to and hide the rest . Each one of those user controls has 30 buttons and I subscribe to button event as following in the constructor : So when I run the Application all th...
Do I have to unsubscribe from button events after using it in c # ?
C_sharp : I have just posted an answer to this question but I 'm not entirely convinced of my answer.There are two things I 'm wondering , consider this code : According to C # Specification 5.0 , there are two different kinds of conversion of as operator . If the compile-time type of E is not dynamic , the operation E...
How is `` as '' operator translated when the right-side operand is generic ?
C_sharp : In a recent question of mine I learned that if there are more than one extension methods with constraints that match the given type , the most specific one will be chosen . This got me thinking - how does the compiler determine which one is `` more specific '' ? And what will the outcome be ? Let 's say I hav...
Generic extension methods in C # : what will happen in this edge case ?
C_sharp : I am trying to filter the results from an explicit load in EntityFramework.The explicit loading works when I do not apply any filter but it does not load results once the filter is applied.ClassesFluent API MappingUsageThis works and populates the student.Grades property.The SQL that is generated looks like t...
Explicit Loading N : M with Filtering
C_sharp : In olden days , you often had a data module that was `` low level '' , did not depend on any other modules , but could be referenced by them , for example to get enums that were used throughout the system.Now we have object oriented interfaces between modules , with calls and events . My question is , should ...
Re-defining the same enum on every object oriented interface in C #
C_sharp : I am new to c # . I have text file with data in it but I want to read particular block line data.Here address can occur multiple times in text file . but i want to capture within thisI want to capture this ip from the block : I tried this code : Expected Output : my expected output is to capture the ip addres...
Fetch particular string from particular block
C_sharp : SAMPLE CODE : VS : Why is it that I always see people creating assigning PropertyChanged to a `` handler '' instead of just using it ? <code> public event PropertyChangedEventHandler PropertyChanged ; private void OnPropertyChanged ( String propertyName ) { PropertyChangedEventHandler handler = PropertyChange...
Events - Handler vs direct access ? Why ?
C_sharp : So I have this code here : What is the best method for me to call the Calculate ( n , time ) function for multiple n values ( given one after the other ) , but the same time . I already thought of using an array to store multiple n values , but is there a better option.Also I would like to pass multiple n 's ...
C # Calling a function with multiple values
C_sharp : I have a string array . What is the simplest way to check if all the elements of the array are numbers <code> string [ ] str = new string [ ] { `` 23 '' , `` 25 '' , `` Ho '' } ;
Easiest way to check numbers
C_sharp : I 'm running into a generics issue while working on a generic Dependency Injection handler ( a base Service Locator ) .Edit 1 ( for clarity ) Okay so I 'm actually using SimpleInjector as a DI resolver and it has the class constraint on it 's GetInstance method , so here is some more complete code : Edit 2 - ...
How can you cast T to a class to match a `` where T : class '' constraint ?
C_sharp : I have the following code for a compiled Linq2sql query to count rows in a table . The query throws an exception despite the same uncompiled query running smoothly : ServiceCustomContext inherits from DataContext and has only ( besides a constructor ) Tables including a table named Current used in the example...
Compiled query fails - Query was compiled for a different mapping source than the one associated with the specified DataContext
C_sharp : The root of my question is that the C # compiler is too smart . It detects a path via which an object could be undefined , so demands that I fill it . In the code , I look at the tables in a DataSet to see if there is one that I want . If not , I create a new one . I know that dtOut will always be assigned a ...
How to avoid creating unneeded object in an elegant way ?
C_sharp : I need to perform a check based on a string value whether its a date or decimal but date parse always return true for decimal.It returns a valid date 3/5/2019.How to validate string to know its a valid date when date format is not known ? <code> string val = `` 3.5 '' ; DateTime oDate = DateTime.Parse ( val )...
Decimal values recognized as DateTime instead of returning false from DateTime.Parse
C_sharp : I have a grid which , when hovered over with the mouse , makes one of its child elements come to life ( opacity from 0 to 1 ) but that grid also can be disposed of ( that grid is part of a listbox that can be remove via a close button on the grid ) .When the user clicks the remove button it also launches the ...
Block MouseLeave trigger if object is disposed of
C_sharp : I can not understand why the code below compiles.At the compile time it is obvious that ( s+1 ) is not a Int16 anymore as we know the value of s.And CLR allows casting to : To its own typeOr any of the base-types ( because it is safe ) As Int32 is not Int16 and Int16 is not base type of Int32.Question : So wh...
Why does C # compiler does not complain with Overflow for this obvious 'bad ' casting ?
C_sharp : Reading the Jon Skeet book , I have found ( some time now ) the use of the `` Named arguments '' in the function call . Here is a fast and easy example : After using it and later see the compiled code I see that the use of this name actually create variables before the call of the function . And this is the c...
Why the use of name arguments in a function actually generate more code ?
C_sharp : I 'm running CultureInfo 1031 ( german ) . IndexOf matches 'straße ' or 'strasse ' with defined 'strasse ' and returns 18 as position . Neither Remove nor Replace got any overload for setting a culture.If I remove 6 chars using Remove 1 character will be left if input-string is 'strasse ' and 'straße ' will w...
ArgumentOutOfRangeException using IndexOf with CultureInfo 1031
C_sharp : Am stuck with small problem.I want to add multiple setConditions for the same Name that is for PublicationTarget . This is using interops dll.For this PublicationTarget , I want to filter with staging & live target and I tried all the ways but no use.Please suggest,1 . Passing xis possible , what is the best ...
Tridion 2009 - Using Interops - Is there a possibility to add multiple setConditions for the same Name
C_sharp : FSharp code is structured as following ( I 'm not in control of the source ) .C # calling code is as follows <code> namespace FS [ < AbstractClass ; Sealed > ] type TestType ( ) = static member IrrelevantFunction ( ) = 0 [ < AutoOpen > ] module Extensions = type TestType with //How do we call this from C # st...
How to call F # type extensions ( static member functions ) from C #
C_sharp : I 'm converting some application code to use NodaTime classes instead of System.DateTime . Part of my application uses the PropertyGrid control to allow a user to edit a class containing both a LocalDate and an Instant . Without changing anything , the PropertyGrid displays the properties okay , but they are ...
How do you use NodaTime Classes in a PropertyGrid ?
C_sharp : I 'm looking at the MSDN docs about List.GetEnumerator.They say the C # method signature is : I was expecting this much simpler signature : What does their signature mean , with all the punctuation and the `` Of '' keyword ? Edit : Well , I guess if no one has seen that syntax , then the MSDN docs are just a ...
public List < ( Of < ( < 'T > ) > ) > .. : :..Enumerator ?
C_sharp : I am either going crazy or missing something entirely here . I have a time entry I am trying to submit with a `` TimeWorked '' attribute whose data type in the SQL server is decimal ( 4,2 ) .When I try to add a time entry with 10.00 as the value for TimeWorked , I get the following error.ErrorCode To InsertDa...
Argument out of range exception for decimal SQL Server EF C #
C_sharp : I 'm trying to work with the optgroup dropdown helper from Serge Zab that can be found here.This is my category table : As you can see I have a category and a category can also be categoryparent from a category . I want to have the parentcategorys as optgroup and the children as options of the optgroup . ( On...
Error using Serge Zab 's helper for optgroup dropdowns
C_sharp : I have a hypothetical question about the efficiency consequences of using exception handling in situations where no exceptions are thrown . First take a look at this C # : I am confident that Dave 's code will be the fastest/most efficient ; while Simon will incur a large penalty for throwing an exception.But...
Exception efficiency when nothing is thrown
C_sharp : In case the title is not completely self-explanatory , here 's the code that puzzles me : I 'm suprised this compiles with no error . It feels like I 'm exposing a private type . Should n't this be illegal ? Maybe your answers will simply be `` There 's no rule against that , so why would n't it be OK ? '' Pe...
Why is it not `` inconsistent accessibility '' to use a private nested type inside a generic type in the interface list ?
C_sharp : I am working on a project where the game world is irregularly shaped ( Think of the shape of a lake ) . this shape has a grid with coordinates placed over it . The game world is only on the inside of the shape . ( Once again , think Lake ) How can I efficiently represent the game world ? I know that many worl...
Representing a Gameworld that is Irregularly shaped
C_sharp : I am facing a problem with UpdateSourceTrigger property . I have a UserControl named LabelWithTextBox , where UpdateSourceTrigger ( On Text Property ) is not defined ( therefore has default value ) . This should stay like this because of performance ( Text should update when Focus is out of the TextBox ) .But...
How to hand over the value of UpdateSourceTrigger to UserControl or update it at runtime ?
C_sharp : Looking for a some help with Ef Core and Linq.Lets say I 'm making big request to receive all support tickets with info about product , company , and so on . It 's quite simple , just joining things : However I have issues with last 4 joins . In project I 'm using Ef Core . That is how I made it ( partially )...
How to map complex linq to object
C_sharp : Why the Linq expression IL results in omission of the Select projection whereas the corresponding method expression keeps the Select projection ? I suppose these two pieces of code does the same.Then why the difference in IL ? EDITED : then why result in SELECT projection even inside IL . it can also be omitt...
Differences in LINQ vs Method expression
C_sharp : I want to understand how chain query is processed . For example , let us consider the following querywhere e.g . numbers= { -1 , 4 , 9 } .Is this what happends behind the scene:1 . Getting all enumerators ( forward pass ) numbers calls GetEnumerator ( ) which returns ( let us denote it with ) IEnum0 instanceI...
Linq : Order of execution chain query
C_sharp : This is not really a question , but an answer which would hopefully help other people.Those who 've written a windows service before , know what a mission it could be to find a bug in it , particularly if it only happens on the live environment . In my case , I had a service that ran smoothly for a couple of ...
Debugging Stack overflow errors on background services
C_sharp : Is there any downside to a class like : If I always want to set this value is there any downside to Example1 ? UPDATE : Session [ `` user '' ] is set in the Global.asax Session_Start . So if this fails . Nothing should work anyways . <code> class Example1 { protected string UserId = ( string ) Session [ `` us...
C # - Downside to Setting Initial Value in Declaration
C_sharp : http : //msdn.microsoft.com/en-us/library/1x308yk8.aspxThis allows me to do this : Rather than : Seems unusual , so I looked at the reflection : Three things struck me : Why does it bother to do the limit check only on the upper bound ? Throwing an ArgumentOutOfRangeException , while index below 0 would give ...
Why does every Char static `` Is ... '' have a string overload , e.g . IsWhiteSpace ( string , Int32 ) ?
C_sharp : I have created the following to expose some data as a regex match string as well as a StringDictionary . It feels like I could do this using LINQ with fewer lines . <code> private const string STREETTYPES = @ '' ALY|Alley|AVE|Avenue|BLVD|Boulevard|CIR|Circle|CT|Court|CTR|Center|DR|Drive|EXPY|Expressway|FWY|Fr...
Looking for a slicker way to convert delimited string to StringDictionary
C_sharp : I have a command as below . I find if I use a file pattern of *.csv it also picks up items with a .csvx extension . Maybe it 's a throwback to the 8.3 filename days - anyone know a way that would return them properly , preferably without rolling our own ? <code> files = ( from file in Directory.EnumerateFiles...
.Net file pattern picks up unwanted files ( C # )
C_sharp : Possible Duplicate : Can I customize automatic event handler generation in Visual Studio ? Can I configure VS2010 Intellisense so that it does this : instead of this : when adding an EventHandler via += and pressing the Shift key ? I understand that this does n't make any difference as far as the generated IL...
Configure VS 2010 so that it does n't add new EventHandler ( ... ) ; when adding an EventHandler via +=
C_sharp : I asked this question . This code does n't compile ( `` Can not convert Generic < T > to T '' ) because of the reason explained here ( even if I 'd expect an InvalidCastException at run-time instead of a compile-time error ) .Accepted solution gave this workaround : My question is : why ? as operator should b...
Unexpected behavior of `` as '' operator , it differs from plain cast
C_sharp : I 've recently started a project that involves using data from a London Ungerground dataset , in order to find routes that are n amount of minutes from a given station . So far I have been able to parse in the data from the dataset , and create possible routes between each station . I have now a list of route...
How do I do list traversal ?
C_sharp : I am not able to figure out the Valid points which can justify that I broke encapsulation or may be otherwise . As per my understanding I am breaking encapsulation as a private method is getting called from another class , Is this enough for justifying that I broke on the laws of OOP . Need to gather some mor...
Did I break Encapsulation ?
C_sharp : I have an array of PropertyInfo representing the properties in a class . Some of these properties are of type ICollection < T > , but T varies across the properties - I have some ICollection < string > , some ICollection < int > , etc.I can easily identify which of the properties are of type ICollection < > b...
How can I find the type of T in a c # Generic collection of T when all I know is the type of the collection ?
C_sharp : I have a datatable with the following information : I only need to remove the next matched items , like this : I tried : Result : Any ideas ? <code> 365.00370.00369.59365.00365.00 - > match with previous item365.00 - > match with previous item 365.00370.00369.59365.00 ( from articlespricehistory in dt.AsEnume...
Linq Distinct only in next rows match
C_sharp : Consider the following code : What does this accomplish that having the public members alone would not ? <code> private string _text = null ; private string [ ] _values = null ; public string Text { get { return _text ; } } public string [ ] Values { get { return _values ; } }
What is the purpose of this approach to access modifiers ?
C_sharp : I Created a Listview with some items.When I click at one , I 'm navigating to new page.When I press back , l 'm going back to the old page ( Main menu page - > item page - > backing to main menu by Frame.GoBack ( ) ) andI see all last clicked items are having gray background.I tried to set background to trans...
How to remove broken background of ListViewItem In UWP ?
C_sharp : I have been reading some C # interview questions and found a permutation of a popular one about delegates the code of which puzzles me.The question was : Predict the output of the code below.The normal version of this question I 've seen declares the i variable before the for loop , thus making it method-wide...
Why is this for iteration variable still around after the for loop ?
C_sharp : Some iterators are faster . I found this out because I heard from Bob Tabor on Channel 9 to never copy and paste.I was in the habit of doing something like this to set array values : This is a simplified example , but in order to not copy and paste , or not type things out again , I suppose I should use a loo...
Why are some iterators faster than others in C # ?
C_sharp : The following snippet evaluates to zero : Whereas , if you do this : The result is ( would you even guess this ? ) int.MinValue . That fact alone is weird enough [ see below ] , but I was under the impression that unchecked was meant to force the compiler into emitting code that pretends not to know that a co...
Weird result from unchecked ( ) , possible compiler bug ?
C_sharp : I am currently trying to implement history tracking on all of my tables in my app in a generic way by overriding the SaveChanges method and making use of reflection . As a simple case , let 's say I have 2 classes/dbsets for my domain objects and a history table for each like the following : The CatHistory cl...
Implementing history tracking in SaveChanges override
C_sharp : There are a few other questions concerning this on SO , but I felt none of them really provided a solid answer.I 'm messing around with reflection a lot lately , and I wanted to check for types contained within a few assemblies that implement a certain interface.So I have a class called BESCollector that impl...
Why are my types not marked as equal ?
C_sharp : It seems like .NET goes out of its way to make strings that are equal by value equal by reference.In LINQPad , I tried the following , hoping it 'd bypass interning string constants : but that returns true . However , I want to create a string that 's reliably distinguishable from any other string object . ( ...
Is it possible to create a string that 's not reference-equal to any other string ?
C_sharp : I have a text file and I am reading it line by line.I want to split a single line with ' , '.But I want the commas which are inside quotes `` '' to be skipped.I have tried following regex and it is not working correctly.How to do it.The contents of file areThe regex is as followsThis regex is outputting the f...
Regex split while reading from file
C_sharp : A bit of domain knowledgeI 'm writing a POS ( Point Of Sales ) software which allows to pay goods or to refund them.When paying or refunding , one need to specify which money transfer mean to use : cash , EFT ( ~=credit card ) , loyalty card , voucher , etc.These money transfer means are a finite and known se...
Mapping the same entity to different tables
C_sharp : In C++ , ' > > ' and ' < < ' are used for cascading during performing the Input/Output Operations.Is there any way in which such things can be done in C # ? Till now , I know that I can take one input at a time and assign it to a variable , for eg , in the following code snippet : whereas in C++ , the same th...
I/O Cascading in c #
C_sharp : When I decompile String.IndexOf ( String ) method , I see this ; In the second parameter definition : if string.LegacyMode is true , StringComparison.Ordinal is evaluated.if string.LegacyMode is false , StringComparison.CurrentCulture is evaluated.But what does String.LegacyMode exactly mean ? When I decompil...
What is String.LegacyMode property for exactly ?
C_sharp : This is something I have n't ever noticed before , but recently ran into . When I encountered this situation , I was surprised at what the compiler considered was correct , and what it forced me to do . I think it is easiest described through example.Let 's say we have a generic base class with a single metho...
Why is my subclass still generic when I supply a type argument to the base class ?
C_sharp : I just wrote this code : It seems very repetitive . Is there a way to generalize this ? So I do n't have to have 4 lines that are the same except a different sign ? ( Note : if there is a better way that does not use the OperationEnum that is great ) <code> private double PerformOperation ( OperationEnum oper...
Can operations be generalized ?
C_sharp : I have a user control that hosts other controls . The way I implemented this is via data templates that define the control that should be associated with a specific view-model . These view-models have similar properties and interaction triggers . Please see XAML snippet below.The problem with this approach is...
Is there anyway of consolidating similar data bindings and/or triggers in XAML ?
C_sharp : First I give a simple example where I know the answer . Consider : and then somewhere the code : We see that am and gm are not considered equal , which is entirely fair ( the latter is an override of the former ) . However , with the last line we can determine that these two methods are related ; one is a `` ...
Determine if two MethodInfo instances represent the same ( non-virtual ) method through inheritance
C_sharp : If I convert single s into decimal d I 've noticed it 's bit representation differs from that of the decimal created directly.For example : Returns ( middle elements removed for brevity ) : Both of these are decimal numbers , which both ( appear ) to be accurately representing 0.01 : Looking at the spec sheds...
Explicit conversion from Single to Decimal results in different bit representation
C_sharp : Now filed on Microsoft Connect ; please upvote if you feel it needs fixing . I 've also simplified the test case a lot : Looking at the IL , as far as I can tell , the C # compiler did everything right , and the bug lies in the JITter.Original question : What is going on here ? This test requires a 64-bit OS ...
Why does this addition of byte* and uint fail to carry into the higher dword ?
C_sharp : I want to perform data-binding to Room.ToNorth.ImageName while ToNorth may be null.I 'm trying to write my own text adventure and have images next to each of the directions a player can go ( ie . open/closed door , pathway ) . When there is n't a room in a given direction I have the controls bound to show a '...
Data binding to a nested property with possibly null parent
C_sharp : Occasionally I find I need to process a list by inserting a new item after each item , except the last one . Similar to how you might put a comma between each item of a list of strings.I got fed up of coding the special case for the last ( or first ) item every time , so I captured the pattern in a Linq-style...
In functional list manipulation , what do we call `` inserting something between each item '' ?
C_sharp : Why does taking the address of a variable eliminate the `` Use of unassigned local variable '' error ? ( Why can we take the address without initialization in the first place ? ) <code> static unsafe void Main ( ) { int x ; int* p = & x ; //No error ? ! x += 2 ; //No error ? ! }
No `` Unassigned Local Variable '' error ?
C_sharp : I get a list of projects using following : Refer following link for more details.But it gives me each and every item in the solution like Directories , projects , etc.I require only projects.How can I get only projects from the solution ? <code> var solution = ( IVsSolution ) Microsoft.VisualStudio.Shell.Pack...
How can I get only projects from the solution ?
C_sharp : I 'm writing a small game in C # using Test Driven Development approach . I 'm facing a problem : I have a class CheckersBoard : And a class BoardGenerator : BoardGenerator allows me to initialize CheckersBoard in a very readable way . So , I really would like to use BoardGenerator in my unit tests to avoid u...
How can I keep my unit tests independent of each other in this simple case ?
C_sharp : Possible Duplicate : Nested using statements in C # I 'm a big fan of the using statement in C # . I find this : ... very much more readable than this : Not only is it more readable , it also prevents accidental use of the foo variable after the using statement ( i.e . after it has been disposed ) , whereas i...
Is it OK to use ` using ` like this ?
C_sharp : In a WCF client application , there are a number of parameterless methods for which we 'd like to cache the results - GetAllFoo ( ) , GetAllBar ( ) . These are used to populate dropdowns and the like , and the results do n't change during the running life of the client.These results are currently being cached...
Is it safe to cache the results of a parameterless method using the method 's MethodHandle as a key ?
C_sharp : I need to generate this simple looking XML , looking for a clean way to generate it . <code> < order > < user > 2343 > < /user > < creditcardtype > 2333 > < /creditcarttype > < country > USA < /country > < orderDetails > < amount > 23434 < /amount > < shipping > 32 < /shipping > < /orderDetails > < /order >
How would you build this xml in c #
C_sharp : I am using a basic State Management system found here : ( code below ) https : //github.com/xDelivered-Patrick/Xamarin.Forms.Essentials/blob/master/Essentials/Controls/State/StateContainer.csWhen implementing , my XAML View looks like the below.The problem is the StackLayout CenterAndExpand is not working . A...
Xamarin Forms State Container View not Respecting Layout Options
C_sharp : I have two classes A & B , where B is derived from A . Both the classes have a method with same signature . They are called in the following manner in Java & c # -- > In case of JAVA : This program generates the following output : -In case of C # : This program generates the following output : -Why does the o...
Why this difference of handling method ambiguity in Java & c # ?
C_sharp : I want to check if any of the items in a list has a field set to trueat the moment I do this : How can I do this using Linq might be trivial to some but ca n't figure if now . <code> bool isPaid = visit.Referrals.Exists ( delegate ( AReferral r ) { return r.IsPaidVisit ; } ) ;
Do List.Exist using Linq
C_sharp : I have a Silverlight app with several graphs and a date control on the top which allows the user to set the date range ( e.g . July 1 - Sep 30 ) . Basically , when a user modifies the date range , a command is executed which sets the ViewModel 's DateRange property to the new value . The DateRange 's setter c...
How to defer data querying in Silverlight ViewModel class ?
C_sharp : This might be really simple but i have a service that returns a string that has a number preceded with zeros . The count of zeros is not predictable but i need to extract the number out of the value . The length of the value is also not constant . For ex . 00001234 , 002345667 , 0000000 , 011 , 00000987 - in ...
extracting integer from string
C_sharp : After considerable measurement , I have identified a hotspot in one of our windows services that I 'd like to optimize . We are processing strings that may have multiple consecutive spaces in it , and we 'd like to reduce to only single spaces . We use a static compiled regex for this task : and then use it a...
How to outperform this regex replacement ?
C_sharp : We have a lot CanExecute tests for a various commands in our project.All tests passed properly when we use Visual Studio testing or AxoCover.We tried to add some previous object initialization , before executing 'CanExecute ' and sometimes it worked ( or we thought that ) .I have a test : Sometimes ( NOT ALWA...
Jenkins failed unit CanExecute test 's methods nondeterministic
C_sharp : Lets say a FIFO ( one which is thread safe ) has items being added to it ( we dont care how ) Now lets say the items ( one by one ) should be inserted to another concurrent collection .The rate of data insertion is dynamic.I want to do it in the fastest way . ( transfer all the elements from the Fifo to the c...
To MultiThread or not to MultiThread ?
C_sharp : What I need to do : I need to capture all shortcut key presses such as Ctrl+S from a specific application . Any key combo , even if it 's not a shortcut for that application.Then my midway application that capture these keys need to validate those key combination and check if another of our apps that are runn...
Capture keyboard shortcuts and forward
C_sharp : We 're writing a diagnostic tool that needs to run for many hours at a time , but we 're running into a mysterious Out of Memory Exception when we try to remove items from a CheckedListBox after the application has run for a couple of hours.We initially tried using checkedListBox.Items.Clear ( ) ; , and after...
CheckedListBox memory leak
C_sharp : I have a custom AuthorizeAttribute in a legacy MVC5 project : We noticed while looking through the logs , that in addition to being to applied to controllers with [ AuthorizeWithLogging ] , it was being called explicitly elsewhere in the code , generating spurious logs : Is there a way to tell ( via StackTrac...
Detecting if AuthorizationAttribute manually called
C_sharp : I have an issue where I 'm using the same template to render some content on a page and the same template is used to render additional content on the page using an AJAX request.The following code renders the partial razor view : The following code makes the AJAX request : So what you get is the same partial r...
TagBuilder not generating unqiue id attribute values across ajax requests
C_sharp : I have the following code : .This code compiles just fine ( why ? ) . However when I try to use it : I get : i.e . MethodToImplement is not visible from outside . But if I do the following changes : Then Main.cs also compiles fine . Why there is a difference between those two ? <code> // IMyInterface.csnamesp...
c # interface question
C_sharp : I 've had a search round the internet and can not find anything that directly matches what I 'm after ... .I have a stored procedure that returns a fixed set of columns ( let 's say ColumnA , ColumnB and ColumnC ) and then additionally returns an indeterminate number / signature of additional columns ( maybe ...
How can I return variable column lengths via LINQ to SQL
C_sharp : I had some verbose code : ... that Resharper offered to elegantize with a LINQ expression like so : ... but the subsequent Resharper inspection says about the code it generated ( above ) : `` Type cast is redundant '' ( referring to the `` c as ComboBox '' part ) , so that it ends up as : Should n't Resharper...
Resharper yanks its own tail ; Is it right the first time or the last ?
C_sharp : Similar question : Passing int list as a parameter to a web user controlIs there any similar example for enum type ? I am creating a asp.net custom control in which I want to pass comma separated list of enums as property.I am writing a TypeConverter for converting comma separated string values to List of Enu...
How to create InstanceDescriptor for List of enum ?
C_sharp : I have a Dictionary data type . My question is , is Dictionary.Keys.ToList ( ) [ i ] always correspond to Dictionary.Values.ToList ( ) [ i ] ? That is , will the following test always passes <code> public void DictionaryTest ( int i , Dictionary < U , T > dict ) { var key = dict.Keys.ToList ( ) [ i ] ; Assert...
Does Dictionary.Keys.List ( ) [ i ] correspond to Dictionary.Values.ToList ( ) [ i ] ?
C_sharp : I 've encountered something quite surprising when using generic constraints with inheritance . I have an overloaded methods Foo that differ with parameter - either base or derived class instance . In both cases it 's generally just passing the instance to the second pair of overloaded methods - Bar.When I cal...
Two-step method resolution with inheritance and generic constraints
C_sharp : I wrote the following method to remove the namespace in brackets from strings.I would like to make this as fast as possible.Is there a way to speed up the following code ? <code> using System ; namespace TestRemoveFast { class Program { static void Main ( string [ ] args ) { string [ ] tests = { `` { http : /...
How can I speed up this method which removes text from a string ?
C_sharp : So , in visual studio , if you type something like this : Then a little tooltip thing pops up saying that you can press TAB to turn it into this : Then if you press TAB again , it generates : Of course , this is very useful . But I find myself more often needing a construction like so : So , is there anyway t...
C # event subscription in Visual Studio 2010
C_sharp : We have an internal app ( Thick Client ) that relies on our central SQL server . The app is a Desktop app that allows the users to work in `` Offline '' mode ( e.g . Outlook ) . What I need to accomplish is a way to accurately tell if SQL is available or not.What I have so far : I currently use the following ...
How to Implement Exchange like availability monitoring of internal SQL Server
C_sharp : On some machines but not on others I get System.ObjectDisposedException using this class . After modifying GenerateDiff ( ) to : I ca n't reproduce the exception.Interesting thing is that this is not working : I 'm using an instance of this class diff here for example . No using or Dispose anywhere . No tasks...
IEnumerable < string > System.ObjectDisposedException
C_sharp : I 'm curious to know if there is such an operator that will allow for the followingInitial line : Desired Line : ( Variable repetition assumption ? ) Im looking to educate myself a little on how these operators work at a lower level , explanation as to why not would be much appreciated.Thanks , <code> if ( fo...
In c # is there such an operator to mean 'AndAlso ' with reference to the first variable ?
C_sharp : I have to strip a file path and get the parent folder.Say my path is I need to getFile Name = File.jogFolder it resides in = FolderBAnd parent folder = FolderAI always have to go 2 levels up from where the file resides.Is there an easier way or is a regular expression the way to go ? <code> \\ServerA\FolderA\...
Do I use a regular expression on this file path ?
C_sharp : I 'm looking for a serializer which could take an instance , and serialize it to a string which would contain c # code , representing the contents of the graph.The class would function similar to SerializeObject in JSON.NET.I know only a very narrow set of structures will work , but the ones I 'm interested i...
Is there a serializer for .net which will output c # code ?
C_sharp : I have a project where I have to take in input of names , weights , and heights and put them into arrays and display them into a TextBox like thisI have been able to populate my arrays but I do not understand how to it output it like the example above . Currently my output is all names , THEN all weights then...
Displaying Multiple Arrays
C_sharp : I am looking for ways of making the following more concise.In particular specifying the type again when creating the mock seems redundant . For example I can write it this way and use reflection to get the type and create the stub automatically : This would work but the compiler can no longer detect that pres...
Getting DRY with Rhino Mocks
C_sharp : How can I find the set of items that occur in 2 or more sequences in a sequence of sequences ? In other words , I want the distinct values that occur in at least 2 of the passed in sequences.Note : This is not the intersect of all sequences but rather , the union of the intersect of all pairs of sequences.Not...
The union of the intersects of the 2 set combinations of a sequence of sequences
C_sharp : Between these two : With Property : With Field : Apparently I 'm supposed to pick the first one . Why ? I 've heard the argument that the point here is to allow interface changes , butif I have the second one , and change it to the first one , no other code shouldever have to change . When recompiled everythi...
Why should I use an automatically implemented property instead of a field ?
C_sharp : I have started to learn c # . I am trying to declare a class and some variables and trying to do a simple concatenation of strings . But i am getting some error - the code is belowThe error i am getting is - a field initializer can not reference the non-static field , method , property 'ConsoleApplication1.Cl...
Need some explaination with beginner C # code
C_sharp : I have a Linq DataContext as a database for the application . I have set up the MVVM pattern and am able to insert new records into the database . However when I load these records and try update them a new instance of the record is being created in the background and being updated with the property changes ....
Windows phone 8 MVVM Linq table Creates new instance on NotifyPropertyChanging
C_sharp : In a website , if I have a class : In a page I have : How many times the query will be compiled ? Every time the page loads ... ? Once in the application ... ? <code> public class Provider { static readonly Func < Entities , IEnumerable < Tag > > AllTags = CompiledQuery.Compile < Entities , IEnumerable < Tag ...
How many times does a compiled query have to recompile during the lifecycle of an application ?