text
stringlengths
46
37.3k
title
stringlengths
12
162
C_sharp : I have this code : I would like to not do the adding of a SeparatorTemplate BUT I would like to do the other tasks on the first run of the foreach . Does anyone have a suggestion on how I can do this ? I want to execute the rest of the code in the foreach but not the line adding the template on the first time...
Is there a way I can determine which row I am on in a foreach loop ?
C_sharp : Suppose I have a table in my database likeand I want every registrant to automatically be deleted , say , 100 days after registering . What is a proper way to do this , and what is the best way ? The shoddy way I was planning on doing it was going to be to create a sproc and in my server-side code invoke that...
Best way in ASP.NET of configuring rows in a database to delete after a certain time
C_sharp : I am stumped by EF 6 ... . I have a web application which behaves very badly in terms of performance . While analysing , I found one of the culprits being a method of mine that checks whether a collection is empty ( or not ) on an EF6 entity.Basically , I have : In my app , I need to check whether or not a gi...
EF6 - not doing what I expected for .Any ( )
C_sharp : I currently know of two ways to make an instance immutable in C # : Method 1 - Compile Time ImmutabilityMethod 2 - Readonly FieldsIt would be nice to have a guarantee that , some instance , once instantiated , will not be changed . const and readonly do this to a small degree , but are limited in their scope ...
Achieving Local Runtime Immutability in C #
C_sharp : I have a 2d arrow rotating to always face the a target ( the target in this case is the cursor ) , the pivot is my player character . I need to restrict this arrow to only follow the target if it is inside an angle of the player , an example would be 90 degrees , so it would only follow if the cursor is in th...
Arrow rotating to face cursor needs to only do so while inside an angle made by two given directions
C_sharp : I have something like this : As you can see this is done on Message.BodyI now what to do the same thing on other string properties on the Message class and I do n't want to duplicate all that code . Is there a way to do that by passing in the property somehow ? <code> public Expression < Func < Message , bool...
Returning Expression < > using various class properties
C_sharp : I have a method that can be called from many threads , but I just want the 1st thread to do some logic inside the method . So , I 'm planning to use a boolean variable . The first thread that comes in , will set the boolean variable to false ( to prevent further threads to come inside ) , and execute the meth...
how to lock on a method content
C_sharp : Simple code that I expect List < int > 's GenericTypeDefinition to contain a generic interface of ICollection < > . Yet I ca n't derive an acceptable type from List < int > which allows me to compare them properly.OutputI would have expected that r1 contained a type that was equal to b.EDITFixed , Jon Skeet g...
Comparing GenericTypeDefinition of interfaces
C_sharp : I have two classes , A and B . B knows about A , and A does n't know about B . B has properties that can be nicely set from A , although there is no inheritance shared between A and B . There will be many times when I need to assign a B 's properties from an A , but I 'm looking for pointers on where I should...
Conventions in assignment code ?
C_sharp : Example 1 : vsExample 2 : Is there any benefit to using the first method over the second , or vice versa ? <code> SomeObject someObject = new SomeObject ( ) ; if ( someObject.Method ( ) ) { //do stuff } //someObject is never used again if ( new SomeObject ( ) .Method ( ) ) { //do stuff }
Is there a benefit to storing an object in a variable before calling a method on it ?
C_sharp : I am using below method to convert byte [ ] to Bitmap : Just wondering if I need to free up any resources here ? Tried calling Marshal.FreeHGlobal ( ptr ) , but I am getting this error : Invalid access to memory location.Can anyone please guide ? Also , FYI , I could use MemoryStream to get Bitmap out of byte...
Marshal - Do I need to free any resources ?
C_sharp : I have two classes ( or models rather ) having some common properties . For instance : I need to write a method that can accept a member selector expression where the member to select can come from either of the two models . This is what I mean : Please note that the selector passed selects both from Model1 a...
Member selector expression combining two classes
C_sharp : I 'm trying to create a wpf project without using auto generate files in VS2010 , I thought it would help me to get a better understanding so I hope this wo n't sound super primitive question . Anyway , after making the xaml file and its code behind e.g . myWindow.xaml and myWindow.xaml.cs I also created App....
Making a WPF project manually
C_sharp : After a build environment update , one of our Smoke Tests broke in TeamCity . Investigation turned out that from the same source code , C : \Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe produces correct binaryC : \Program Files ( x86 ) \MSBuild\14.0\bin\MSBuild.exe produces incorrect binaryWhen does...
MSBuild v14 compiles a semantically incorrect assembly under some rare circumstances
C_sharp : i do n't want to say : i want something like : Is this possible or is there also something else besides ! = . <code> ( trsaz ! = v1 ) & & ( trsaz ! = v2 ) & & ... trsaz ! = ( v1 , v4 , v7 , v11 )
How do i say is not , is not
C_sharp : This question occurred to me when an answer was proposed to another question I asked . Suppose I have a base classwith some decent number of derived classes- let 's say more than half a dozen . Most of those derived classes share no similarity beyond what they inherit from the base class , but two of them hav...
How aggressively should I subclass to keep DRY ?
C_sharp : I would like to check in runtime that a variable of type Func < ... > is a specific class method.E.g . <code> class Foo { public static int MyMethod ( int a , int b ) { // ... } } Func < int , int , int > myFunc ; myFunc = Foo.MyMethod ; if ( myFunc is Foo.MyMethod ) { //do something }
How to check if a variable of type Func < ... > is a specific class method
C_sharp : How can I call this constructor ? I thought of but I want to avoid object creation.So is this one ok ? <code> public class DataField { public String Name ; public Type TheType ; public DataField ( string name , Type T ) { Name = name ; TheType = T ; } } f = new DataField ( `` Name '' , typeof ( new String ( )...
How to pass a type to a method ?
C_sharp : I am learning OOP and have a question about what is exactly happening with the code below.I have the classic Dog Animal example going . Dog inherits Animal.Both questions are based on this assignment : Animal a = new Dog ( ) ; What is actually happening when I declare an Animal and set it to a Dog reference ....
What is happening with inheritance in my example ? And , what is the proper terminology in c # ?
C_sharp : I have a XAML UserControl embedded in a WinForms/WPF Interop ElementHost control . The control is pretty simple - it 's just a dropdown with a button - here 's the entire markup : The problem is that it does n't work reliably , and far from instinctively.If I type something in the box that actually matches an...
Why does my dropdown feel so clunky ?
C_sharp : I am writing a function for an item service where if the user requests for all items under a certain name it will return them all . Such as all the phones that are iPhone X 's etc.I got help to make one of the functions work where if there are more than 1 items it will return them all ( this is the third case...
What is the purpose of the parenthesis in this switch and case label ?
C_sharp : I 'm constructing arbitrary objects from DataRows using Reflection , and when the rubber finally meets the road , I need to take a value from the DataRow and assign it to the property on the object.Because DataRows can be full of types that do n't support conversion , many of these result in exceptions that h...
Is there any way to test my conversions to avoid using exceptions ?
C_sharp : The Microsoft.Office.Interop.Word._Document interface has a method with the following signature : A few points I am having trouble understanding : A ref parameter can not have a default value.A default value has to be a constant , and Type.Missing is not.When calling this method , I can use Close ( false ) - ...
Understand COM c # interfaces
C_sharp : I have the following snippet : It treats x @ product.Count as a literal . How can I have a character placed right before the @ symbol ? <code> < ul > @ foreach ( var product in Model.Products ) { < li > @ product.Name x @ product.Count < /li > } < /ul >
Why does n't razor detect this as a code block in ASP.NET MVC ?
C_sharp : I do n't understand the order of execution in the following code . Here the numbers that satisfied the first Where clause are ( 4 , 10 , 3 , 7 ) , and the numbers that satisfied the second Where clause are 2 and 1 , after that we have function Aggregate that subtract them and make one element from both . My q...
LINQ execution flow ( homework )
C_sharp : I have encountered a performance issue in .NET Core 2.1 that I am trying to understand . The code for this can be found here : https : //github.com/mike-eee/StructureActivationHere is the relavant benchmark code via BenchmarkDotNet : From the outset , I would expect Activated to be faster as it does not store...
Is Activating a Struct Without Storing It as a Local Variable Expected to Be Slower than Not Storing It as a Local Variable ?
C_sharp : We are indexing documents into Solr using Solrnet in asp.net c # project . We are having requirement where Solr DIH can not be used , so we are indexing products in certain batches to Solr using following code : With huge document size , it takes lot of time ( most of times it takes few hours ) to complete wh...
Stop the for-loop in-between before it completes
C_sharp : I am working on a small project using C # and EF5.0 and I need to group some data . Let say I have table of columns in a building like shown below.I need a C # code to see the above data groupped like this : I prefer clues than the exact solution.EDIT : Below code shows my current state . I think I can find t...
Data grouping in SQL
C_sharp : While refactoring some code written by someone else , I 've come across some weirdness that I do n't understand , and I 'm hoping someone can explain why it happens.What I thought would happen here would be that as brackets have the highest precedence , the assignment inside the brackets would happen first an...
Evaluation of expressions within an if statement
C_sharp : A piece of C # code I got result false in code execution , but when I copy that code into WATCH window , the result is true . <code> var isTrue = ( new List < int > { 1,2,3 } is IEnumerable < object > ) ;
VS debug issue , who can help me to explain this below ?
C_sharp : Ive got what I think may be an unusual problem ( Ive searched around a lot for an answer , but I dont think Ive found one ) .I have messages that are read from a queue and depending on the message type contains a payload that needs to be deserialized into a concrete c # class . This needs to eventually be con...
Factory class using generics but without base class
C_sharp : I have textbox that I use for diagnostic purposes . The code behind is really simple : XAML : C # : How can I define that each new input is on a different line ? Because right now all errors are in just 1 long line . 14:15:00 Error 1 14:16:00 Error 2 14:17:00 Error 3Instead of readable with line breaks betwee...
Next text input on different line
C_sharp : I have a class that looks like this : For the moment , I have each of the first 3 methods call SomeSpecialMethod ( ) just before these method return . I 'm going to add about 15 more methods that in the end all need to execute SomeSpecialMethod ( ) and I 'm wondering if there 's a way to say `` when any of th...
executing a method after several methods run
C_sharp : Basically I have an object rotating . It is a click and drag type of rotation , but when the object is facing the -z -x corner , or bottom left corner , it has a chance of completely flipping 180 degrees the opposite way when clicked again . This is very troublesome and I even know what line this takes place ...
Object flips 180 degrees on z-axis in -z and -x corner
C_sharp : I 've a ListView whose data I select and send to a DataGrid . I am having trouble with the quantity column of the DataGrid which I would want to calculate how many times a ListView item has been added to the said DataGrid ( I 'm currently displaying a success message when the same item is selected ) . I would...
How to Add a Quantity Column on a DataGrid from ListView selection in WPF
C_sharp : At first , I do not use dynamic , I just use the code like this , and it works well.But when I change it to dynamic,it is wrong.and I add a method like this , I build the project it show that List do not have the AsQueryable method.How to change it ? <code> List < Student > result2 = StudentRepository.GetStud...
What is the difference between my codes when I use 'dynamic ' to use AsQueryable method ?
C_sharp : I am trying to post a file to an iManage server REST interface ( Apache server , java backend ? ? not sure ) . Postman works fine , but when I try it from C # .NET CORE 3.1 I get a response like so : { `` error '' : { `` code '' : `` FileUploadFailure '' , '' message '' : `` File upload failure '' } } Anyone ...
Can not Upload File using C # HttpClient , Postman works OK
C_sharp : I 'm attempting to create a JSON request to send to email service GetResponse to add a contact to a mail campaign.The format I 'm trying to achieve is for add_contactFollowing How to create JSON string in C # I contructed this setupAnd filled this like soHere json is as expectedWhat I do n't know is how to pr...
Creating a specific JSON format
C_sharp : I was trying to better understand string 's interning in c # and got into the following situation : I 'm getting the following result in console : True True True False The mistake for me is that why is the 4th false ? <code> string a = '' Hello '' ; string b = '' Hello '' ; string c = new string ( new char [ ...
False after casting interned strings to objects
C_sharp : Possible Duplicate : When do you use code blocks ? Ok , this might be a stupid question and I might be missing something obvious but as I slowly learn C # this has kept nagging me for a while now.The following code obviously compiles just fine : I understand that { } blocks can be used for scoping . The quest...
Benefits of scoping blocks ?
C_sharp : I have one array : I m looking for the index of BMW , and I using below code to get : Unfortunately it return the result for the first BMW index only . Current output : My expected output will be <code> string [ ] cars = { `` Volvo '' , `` BMW '' , `` Volvo '' , `` Mazda '' , '' BMW '' , '' BMW '' } ; Label1....
Get the list of index for a string in an array ?
C_sharp : I wanted to do trim by default white-space characters and by my additional characters . And I did this by following way : As for me it is looks like stupid , because it has more iterations than it needs . Is it possible to add characters ( instead replace defaults ) for string.Trim ( ) ? Or where can I found ...
Is it possible to add characters ( instead replace defaults ) for string.Trim ( ) ?
C_sharp : Here is a seemingly simple class to sum all elements in an array : Of course this is not an efficient way to perform this task . And this is also very inefficient usage of threads . This class is written to illustrate a basic divide and conquer solution concept , and it hopefully does so.Here is also a simple...
Incorrect result with too many threads
C_sharp : I read a lot of articles about number format string , ex : http : //msdn.microsoft.com/en-us/library/0c899ak8.aspxI really not understand how to write the best format string . To get a excepted result , I can write some ways . Example : print number 1234567890 as a text `` 1,234,567,890 '' . These ways give t...
How to get the best number format string ?
C_sharp : I have these two functions which read a stream into a buffer and loads it into the given struct.I 'd like to combine these into a generic function to take either of the structs , I 'm just unsure what the proper way to do this is.Is this the correct way ? <code> TestStruct1 ReadRecFromStream2 ( Stream stream ...
How to make these struct functions generic ?
C_sharp : I recently stumbled upon an odd issue which I could not explain and I would be glad if someone could clarify why it happens.The issue I 've encountered is as follows : I have an interface which is implemented , like so : And another interface which is implemented in a different project , like so : I have an o...
Object instantiation fails when using overloaded constructor
C_sharp : So I took a look at ILDASM , inspecting a .exe which looks like this : Now , the CIL code looks like that : I understand that first b is loaded ( which is stored at [ 1 ] ) , then a constant with the value of 1 and then they are compared . What I do not understand is why another constant with the value 0 is l...
What exactly does the == operator do ?
C_sharp : Using TPL with .NET 4 , I 'm trying to decide how to design APIs that deal with futures . One possibility that occurred to me was to mimic the async pattern but without an End ( IAsyncResult ) method : As such , callers can decide whether to call the blocking or non-blocking version of GetAge ( ) . Moreover ,...
Does this TPL idiom exist ?
C_sharp : Here is some example code : Since DateTime can not be null , why does this code compile ? Edit : The issue is not just that this code will always return false , but why something like DateTime which is never null is allowed in such a comparison . <code> static DateTime time ; if ( time == null ) { /* do somet...
Why is this a valid comparison
C_sharp : I have 2 linq statements - currently in the middle of a switch block . The statements are below.As you can see the only difference is that they refer to two different properties of `` lender '' , however , all the elements used in the linq query are identical in `` ApplicationWindows '' and `` TransferWindows...
Is it possible to make 1 generic method out of these 2 linq statements ?
C_sharp : In the following example , I have two constraints , Foobar and IFoobar < T > , on type T in generic class FoobarList < T > . But the compiler gives an error : Can not implicitly convert type 'Foobar ' to 'T ' . An explicit conversion exists ( are you missing a cast ? ) It seems the compiler considers CreateFo...
Priorities of multiple constraints on a generic type parameter
C_sharp : I wonder what is the reason for the invocation of the method that prints `` double in derived '' . I did n't find any clue for it in the C # specification . <code> public class A { public virtual void Print ( int x ) { Console.WriteLine ( `` int in base '' ) ; } } public class B : A { public override void Pri...
C # Overloaded method invocation with Inheritance
C_sharp : In the given class I 've specified a generic as the type to extend via the this keyword . Being that I 've delayed the definition of the type until compile time , how does intellisense ( and anything else involved ) know what type I am extending ? Does C # simply default to the top level System.Object ? <code...
What are we extending when creating a generic extension method ?
C_sharp : I have two datatables , I am trying to copy row from one table to another , I have tried this . the thing is that my tables are not exactly the same , both tables have common headers , but to the second table have more columns , therefore I need `` smart '' copy , i.e to copy the row according to the column h...
Copy row from datatable to another where there are common column headers
C_sharp : In my page load , am I calling ReturnStuff ( ) once or three times ? If I am calling it three times , is there a more efficient way to do this ? <code> protected void Page_Load ( object sender , EventArgs e ) { string thing1 = ReturnStuff ( username , password ) [ 0 ] ; string thing2 = ReturnStuff ( username ...
Am I using Lists correctly ?
C_sharp : Is there a way to shrink these into just one group result ? I have a set of pages like these which simply return static content and thought there must be a more efficient way to do it . EDIT : Thanks for all the replies : ) <code> public ActionResult Research ( ) { return View ( ) ; } public ActionResult Faci...
Can I simplify this code for return views ? It seems very redundant
C_sharp : I was hoping someone might help me understand why Convert.ToDecimal when used within linq is rounding a decimal and when used outside , it does notGiven the following DB : CODE : Output <code> CREATE TABLE [ dbo ] . [ Widgets ] ( [ ID ] [ int ] NOT NULL , [ WidgetName ] [ varchar ] ( 50 ) NOT NULL , [ UnitsAv...
Why is Convert.ToDecimal returning different values
C_sharp : Though I can successfully do this at the top of a page : and then use a class like this later : I really would like to do this : so that I can use it like this later : but that gives me the error : The 'tagprefix ' attribute can not be an empty string.Is n't there a way to register an empty TagPrefix so it ca...
Use an empty TagPrefix with a < % @ Register % >
C_sharp : I have a list of objects of the same type that each has a property that is an array of floats . Taking this list as input , what is the easiest way to return a new array that is the average of the arrays in the list ? The input objects look like this : The DataValues arrays will be guaranteed to have the same...
Elegant averaging of arrays from different instances of an object in C #
C_sharp : After reading Stephen Cleary blog post about eliding async and await I 've decided to go and play around with it . I wrote very simple console app with HttpClient using Visual Studio For Mac.According to blog post it should throw an exception but it did n't . If I switch to Windows and try to run this app , I...
Eliding async and await on HttpClient is not throwing exception on OSX
C_sharp : I am using Entity Framework 4.3.1 using the DbContext POCO approach against a SQL Server 2012 database . I have just two tables in the database and they look like this : NOTE : There are no foreign keys specified in the database at all - I am only enforcing the relationship in the model ( I can not change the...
Why would a datetime prevent a navigation property from getting loaded ?
C_sharp : I am working on some class room examples . This code works but I do not see why it works . I know that there is a generic type and that class implements Item but Item is just another class . Why would this code allow a int and double into the same list.I am sure that it has to do with the Generic but why I am...
Why does this code work for different types ?
C_sharp : I am new to CSharp.I have seen `` this ( ) '' in some code.My question is Suppose if i callParemeterized constructor , am i invoking the paremeterless constructor forcefully ? .But According to constructor construction , i believe parameterless constructor will be executed first.Can you please explain this wi...
Using this ( ) in code
C_sharp : For example , if I have a class : and later create two instances of it : and call r sequentially , the r for both will give the same values . I 've read that this is because the default constructor for Random uses the time to provide `` randomness , '' so I was wondering how I could prevent this . Thanks in a...
How do I have two randoms in a row give different values ?
C_sharp : I know other people wrote similar questions , but I think mine is a different case , since I could n't find any solution.I have an object assignment , something very simple like this : the assembly code generated is the followingnow , just for to understand what 's going on , I wanted to step inside the call ...
Mysterious call is added when reference is assigned in c #
C_sharp : I have a view that displays a boolean ( currently defaulted to 0 ) in a box format in the view that I can not check to activate as true and also want to enter text in the result field to pass back to the controller and save both changes to a table . Can someone please explain what I have to do to allow this f...
Enable boolean and enter text in view then pass back to controller - MVC
C_sharp : I 've seen most people use member variables in a class like : But what 's the difference of that to this ? <code> string _foo ; public string foo { get { return _foo ; } ; private set { _foo = value } ; } public string foo { get ; private set ; }
Why use member variables in a class
C_sharp : Does anybody know how to write an extension function returning a ParallelQuery in PLINQ ? More specifically , I have the following problem : I want to perform a transformation within a PLINQ query that needs an engine , whose creation is costly and which can not be accessed concurrently.I could do the followi...
How do I write a thread-aware extension function for PLINQ ?
C_sharp : In Haskell , the language I 'm most familiar with , there is a fairly precise way to determine the type of a variable . However , in the process of learning C # , I 've become somewhat confused in this regard . For example , the signature for the Array.Sort method is : Yet , this method will raise an exceptio...
How do I determine the appropriate type for method parameters in C # ?
C_sharp : This is the xml stream : The corresponding classes look like this : the code to deserialise the xml ( the string replacement contains the xml code ) : The method stringToStreamThe result that i get is as following : The object XmlData is made and there is a list of taskEvents.The problem is in the list itself...
deserialising does not work
C_sharp : I have seen people define their events like this : Can somebody explain how this is different from defining it without it ? Is it to avoid checking for null when raising the event ? <code> public event EventHandler < EventArgs > MyEvent = delegate { } ;
Why is this event declared with an anonymous delegate ?
C_sharp : This is probably a very beginner question but I have searched a lot of topics and could n't really find the same situation , although I 'm sure this kind of situation happens all the time.My project/program is going to track changes to drawings on construction projects and send notifications to people when dr...
Circular reference — architecture question
C_sharp : Given the code block above does not actually do anything but call the first DoSomethingElse method , what would be a clever approach to having the correct method call based on the real type of the parameters passed to the DoSomething method ? Is there a way I can get the method call resolved at runtime , or d...
C # enhanced Method overload resolution
C_sharp : Calling _thread.Join ( ) causes the GetConsumingEnumerable loop to be stuck on the last element . Why does this behavior occur ? The context for this approach is that I need to make sure that all operations are executed on one OS thread , which would allow a part of the app to use different credentials than t...
Thread Join ( ) causes Task.RunSynchronously not to finish
C_sharp : In C # you are recommended to add the [ Flags ] attribute to bitmask enumerations , like so : I discovered I had code that erroneously performed bitwise operations on an enumeration without the [ Flags ] attribute that was not a bitmask at all ( First=1 , Second=2 , Third=3 , etc. ) . This was of course logic...
Possible to prevent accidental bitwise operators on non-bitmask field ?
C_sharp : I 'm trying to write an extension method that , given a value , will returnThe value itself if it 's different from DBNull.ValueThe default value for value 's typeYeah , that 's not the clearest explanation , maybe some code will make what I 'm trying to accomplish obvious.As long as value 's boxed type is th...
Casting boxed byte
C_sharp : I have an Item class that has a publicly accessible member NoSetter that does not contain a setter . The object does explicitly state a get , which retrieves a private readonly List object.When you create this object , you ca n't set NoSetter to a list , the compiler fails whenever you try . However if you cr...
How does an inline list override a property with no setter ?
C_sharp : i have code . the constructor should enter the GetItems function but when i place breakpoint , it simply do not stop.what is the problem ? <code> namespace Storehouse { public partial class MainForm : Form { public MainForm ( ) { InitializeComponent ( ) ; var a = GetItems ( fILEToolStripMenuItem ) ; } public ...
constructor do not enter a function C #
C_sharp : I ran into an issue the other day that I first believed to be an issue with Entity Framework . I posted a question about it the other day here . Since then , I have determined that this issue is not related to Entity Framework.Consider the following classes : If I add the following code to the Main method of ...
Peculiar Issue When Using Expressions and ( Web ) Console Application
C_sharp : why can we have a static circular reference in struct but not a instance type circular reference ? <code> struct C { //following line is not allowed . Compile time error . // it 's a non static circular reference . public C c1 ; //But this line compiles fine . //static circular reference . public static C c2 ...
Why is Circular reference in struct of instance type not allowed but circular reference of static type allowed ?
C_sharp : I have this model class : Then I add a few records in the database : Then I run this query : And I get : user2 Collection2 user1Why in Collection2 do I have a record ? And how to fix it ? UPDATE.This is a link to the test project https : //drive.google.com/file/d/0BxP-1gZwSGL5S1c4cWN1Q2NsYVU/view <code> publi...
Strange behavior of Entity Framework
C_sharp : I have a variable of type Func < dynamic > and I am trying to assign it a value . If I assign it to a method that returns a value type ( e.g . int ) , I get the error 'int MethodName ( ) ' has the wrong return typeIf I wrap the method in a lambda call , however , it works fine . Also methods that return refer...
Ca n't assign methods that return value types to Func < dynamic >
C_sharp : The problem is after running Temp totals is an IEnumerable that contains a IEnumerable of a simple class of The idea is to then take this data and group it into a dictionary so that i can get a total of all of the amounts with the key being the type.The end result should look like : I know that I could just f...
Turning an IEnumerable of IEnumerables into a dictionary
C_sharp : Let 's say I have a following C # interface : And SomeClass is defined as follows : Now I 'd like to define the implementation of the interface , which wo n't compile : before I change it to : Would n't it make sense that the type constraints are also `` inherited '' ( not the right word , I know ) from the i...
Why does a generic class implementing a generic interface with type constraints need to repeat these constraints ?
C_sharp : I have some values . I want to run the shift for 6 days . but after each 2 days Shift id 1 rotate to shift id 2 and again after two days shift id 2 rotate to shift id 1 and so on ... My output should be likeI am getting shift id through a foreach loop . I tried like below mentioned way but not getting a prope...
How to iterate date in for loop ?
C_sharp : I 'm attempting to parse key-value pairs from strings which look suspiciously like markup using .Net Core 2.1.Considering the sample Program.cs file below ... My Questions Are:1.How can I write the pattern kvp to behave as `` Key and Value if exists '' instead of `` Key or Value '' as it currently behaves ? F...
.Net Core Regular Expressions , Named groups , nested groups , backreferences and lazy qualifier
C_sharp : Hi guys I wrote a simple program that split a string in the argument into number , letter and operators , however I come across that 23x+3=8I found the output is separate into each char 2 and 3 i want to have 23 as a whole number . is there way to push 2 number together ? <code> foreach ( char x in args [ i ]...
Separate int and char and making whole number
C_sharp : I am reading Concurrency in C # by Stephen Cleary in which there is an example that has puzzled me for a while . Normally the LINQ Select method requires a lambda method that returns the value for the result collection.In the book on page 30 there is an example where the lambda does n't return anything , but ...
Why does n't an async LINQ Select lambda require a return value
C_sharp : When going over the project source code , I stumbled upon a method and wondered about one thing . Are the following two methods EXACTLY same from the performance/memory/compiler point of view ? Is the return variable automatically created by compiler ? <code> public static string Foo ( string inputVar ) { str...
Is return variable automatically created by compiler ?
C_sharp : Scenario : I 'm trying to use Roslyn to merge a set of C # source fragments into a single code fragment.Issue : when parsing different classes with a leading comment , the comment above the first class ( SomeClass in the example ) is not preserved . For the second class ( AnotherClass ) , the comment IS prese...
merging C # code with roslyn : comment disappears
C_sharp : I was following the guidelines by MSDN . Two questions : Have I correctly implemented the equals method ? Could someone show me how to implement GetHashCode Correctly for my class ? MSDN does x ^ y , but I ca n't do it for mine . <code> using System ; using System.Collections.Generic ; using System.Linq ; usi...
C # Implementing the Equals Method Correctly and How do I implement the GetHashCode Method
C_sharp : I have two classes , BaseClass and Person . The Person class inherits from BaseClass . I then use the following generic method.Within the BaseClass I have a method , that invokes GetPropertyI then call this method from a unit test.When typeof ( T ) is used , BaseClass is returned . If I use item.GetType ( ) t...
Why is generic type not the correct type ?
C_sharp : ExampleI call the inherited ClassB constructor . I pass in a null . ToLower ( ) throws an exception on a null . I want to check for a null before that happens . How can I do this ? <code> public class ClassA { public ClassA ( string someString ) { } } public class ClassB : ClassA { public ClassB ( string some...
How do I do operations on an inherited base constructor in C # ?
C_sharp : what is the use of declaring like this to declare a private variablenow normally in the coding we use ID directly which in turn access the _ID which is private.How this offers more security instead of directly declaring as <code> private Int64 _ID ; public Int64 ID { get { return _ID ; } set { _ID = value ; }...
Private variable accessing
C_sharp : I 'm trying out Roslyn 's code-generation capabilities using LinqPad to run fragments . LinqPad 's .Dump ( ) extension method renders a formatted view of the object to the Result pane.The code generated by http : //roslynquoter.azurewebsites.net/ includes a lot of code that does n't seem to do much other than...
Are Roslyn 's `` .WithFooToken ( ) '' calls superfluous ?
C_sharp : Given the following code packing four byte values into a uint.Is it possible to apply mathematical operators like * , + , / and - on the value in a manner that it can be unpacked into the correct byte equivalent ? EDIT.To clarify , if I attempt to multiply the value by another packed valueThen unpack using th...
Mathematical operations on packed numerical values
C_sharp : I have this code : it outputs me : But , I thought it should be : Because Baz is overriding the method . What is happening here ? Am I missing something ? Why did the output for fooBaz.Test ( ) is `` Foo '' instead of `` Baz '' ? <code> using System ; namespace Test { class Program { static void Main ( string...
c # 6 bug ? virtual new method strange behavior
C_sharp : Let 's assume , that we have the following classes : All of these classes are actually a lot longer , but also similar in the same degree . Is there a ( nice ) way of converting them all to one generic class ? The core problem is the line : because C # disallows calling parametrized ctors on generic class spe...
Refactoring with generics
C_sharp : I am looking at some covariance/contravariance stuff , I have a much wider question but it all boils down to this : This does n't work , even though BaseEntity is the parent abstract class of ProductStyle , is there a way of achieving this ? <code> GenericRepository < BaseEntity > repo = new GenericRepository...
Generics - Using parent class to specify type in generics
C_sharp : I am having trouble with this , as I have difficulty properly formulating it too . Making it harder to google it . I will try to explain as clearly as possible . I 've simplified the code to make it clearer what my question isI have an abstract class that has methods and properties that are used by all clases...
How to refer to an enum in the actual class rather than the base class in C #