Browsing 7239 questions and answers with Jon Skeet

LINQ does not recognize joined table in select clause

I am left joining expected records to a returned set and attempting to determine if the expected column was updated correctly. The Column to be updated is determined by a string...
Jon Skeet
people
quotationmark

Yes, dbRow is only in scope within the equals part of the join. However, you're not using your r range variable - which contains the matched rows for the current addRow... or null. Just change each dbRow in the select to r. But then work... more 12/11/2015 5:57:41 PM

people

reflection to invoke methods of unknown property types

I want to call the generic method, 'get_', for each property, IEnumerable<class>, of my view model class to avoid creating lengthy switch statements that explicitly get...
Jon Skeet
people
quotationmark

I would use something like: foreach (var prop in vm.GetType() .GetProperties() .Where(x => x.GetCustomAttributes<ExportAttribute>().Any())) { var list = (IEnumerable)... more 12/11/2015 5:48:26 PM

people

XmlDocument rearrange XmlNodes C#

I have an XML Document that stores all sorts of information about users of a system. Utlimately, the nodes that I am intersted in I hae outined below. So, there is a user that...
Jon Skeet
people
quotationmark

Here's an example for adding a new root element: using System; using System.Xml; class Test { static void Main() { XmlDocument doc = new XmlDocument(); doc.Load("test.xml"); var originalRoot =... more 12/11/2015 5:20:45 PM

people

UWP vs WPF: System.Globalization CultureInfo is different?

Setup: VS2015 C# solution Contains one UWP project Contains one WPF project Both projects declare var ci = new CultureInfo(1) Question(s): Why does the WPF project find the...
Jon Skeet
people
quotationmark

Yes, basically some members are available on some platforms but not others. Look at the version information for CultureInfo(int) constructor vs CultureInfo.DateTimeFormat in the Version Information section, as an example. Constructor... more 12/11/2015 5:10:53 PM

people

Why get accessor does not allow the modification of object returned?

Please have a look at the code below: public class Foo { public System.Windows.Rect s { get; set; } public Foo() { s = new...
Jon Skeet
people
quotationmark

System.Windows.Rect is a structure. Therefore a copy of the struct is returned by the property, rather than a copy of a reference to an object. Modifying the returned value does nothing, as it's a copy of the value that's actually stored... more 12/11/2015 4:56:59 PM

people

In a derived class, how to have a property of a derived type from the type of the property in the base class?

This is a huge design problem that I often encounter and I think it is because I don't understand OOP right. Here is the class of the base Property : public class BasePropety...
Jon Skeet
people
quotationmark

Sounds like you need generics instead: public class BaseClass<T> where T : BaseProperty { public T Property { get; set; } } public class DerivedClass : BaseClass<DerivedProperty> { public void MethodExample() { ... more 12/11/2015 4:24:16 PM

people

How to resolve "data exception: invalid character value for cast" in java?

I am creating an application in which I am using Access database. I have to insert a few values in the database but I get an error "data exception: invalid character value for...
Jon Skeet
people
quotationmark

Your values are in a different order to the columns you've specified, basically. You're trying to populate: MRNumber: 'ABC124' Address: 'Billi' Age: 'Billa' Gender: 'Rafa' Contact: 21 CNIC: 'Female' Consultant: '123' PatientName:... more 12/11/2015 3:04:05 PM

people

c# result in mysql = System.Collections.Generic.List

in table "skupina" we have values "pc1,pc2,pc3,...". But in this code I have result in mysql System.Collections.Generic.List, but should be "pc1,pc2,pc3,....". Where is my...
Jon Skeet
people
quotationmark

You're implicitly calling ToString() on a List<T>. That doesn't do what you expect it to, because List<T> doesn't override ToString(). You can use // Note: the ToArray() call is only required if you're targeting .NET 3.5,... more 12/11/2015 1:40:09 PM

people

VS 2015 marking warning as erros

My VS 2015 is treating warnings, such as "Virtual member called in constructor", as error! Compilation still completes the code is sprinkled with red underlines and the error list...
Jon Skeet
people
quotationmark

You go to your project properties page, and in Build tab, find the "Treat warnings as errors" radio button, then select "None" - or just specific warnings that you want to highlight as errors. more 12/11/2015 12:10:27 PM

people

Replace foreach with lambda while updating list

I want to update vmlist by geting values from vlist without using any foreach loop. For now I am just doing this with foreach loop, but I want to replace this foreach with...
Jon Skeet
people
quotationmark

Your current approach is very inefficient - it's O(N * M) and it creates a list on each iteration. Using a join would be more efficient - I would still use a foreach loop, but separate the querying part from the update part: var... more 12/11/2015 12:08:51 PM

people