Browsing 7239 questions and answers with Jon Skeet

Precedence in Java

Unary postfix increment and decrement operators have more preceedence than relational operators according to precedence table, so why in a expression like this (x++ =10) the...
Jon Skeet
people
quotationmark

The operator isn't evaluated first. The ordering is: Evaluate LHS (x++) - the result is the original value of x, then x is incremented Evaluate RHS (10) - the result is 10 Compare the results of the LHS and RHS Here's code to... more 7/11/2017 8:20:46 AM

people

Derived Class using Parent Method

Why can't i access the age method from either class A or B? I thought because it's a protected method, derived class instances should be able to use it? class Program { ...
Jon Skeet
people
quotationmark

Protected means it can be used from code in the derived classes - it doesn't mean it can be used "from the outside" when working with derived classes. The protected modifier can be somewhat tricky, because even a derived class can only... more 7/11/2017 5:46:28 AM

people

LINQ OrderBy based on row values

Lets say we have two tables Parent "DocumentCodes" and Child "Documents". DocumentCodes table have columns DID,DocumentName,PrintOrder and AscOrDesc Documents table have columns...
Jon Skeet
people
quotationmark

The situation is a fairly ugly one, given that two result rows could theoretically be compared which have the same PrintOrder but different AscOrDesc values. It's only the source of the data that's preventing that. I do have a horrible... more 7/10/2017 4:04:49 PM

people

Generic class and simplified constrains?

Lets say I've got a generic interface IFace<T, U>. The T and U can be constrained in some additional way, but I don't think this is relevant to the problem. I'd like to...
Jon Skeet
people
quotationmark

Is this possible, or do I NEED to specify the T and U generic parameters? You need them, I'm afraid. You'll need to have class GenClass<T, TX, TY> where T : IFace<TX, TY> That's assuming you can't create a non-generic... more 7/10/2017 8:10:25 AM

people

Importance of getting resolved at run time or compile time for .GetType () and Typeof () in c#

I recently read and article about .GetType () and Typeof () methods in c#. Now, I know that both of them return System. Type. That article also indicated that it's important to...
Jon Skeet
people
quotationmark

typeof isn't a method - it's an operator. That's how it's resolved at compile time. They don't do the same thing, in that for typeof you need to know the actual type or type parameter1 you want at compile-time, whereas for GetType you... more 7/8/2017 8:50:42 PM

people

Can you create an initialize method for DLL?

I need to create a service, but the service needs to be in a already existing Class Library file and also the new service needs to start running after the Class Library is...
Jon Skeet
people
quotationmark

No, class libraries don't support initialization like this. Note that the library wouldn't even be loaded until it's first used anyway. You could write a type initializer for some appropriate type, and make that start the service - but... more 7/7/2017 7:48:56 AM

people

StringBuilder and string equality check

I am trying this sample of code and OpTest when System.Console.WriteLine(s == t); it returns false. Can somebody explain this? public static void OpTest<T>(T s, T t) where...
Jon Skeet
people
quotationmark

Your generic method will basically be performing a reference equality check - and the values of s1 and s2 refer to different but equal strings. You can show this more easily like this: string x = "test"; string y = new... more 7/7/2017 7:26:08 AM

people

Remove last character from dictionary<string, dictionary<string, string>> using C#

I have Dictionary<string, Dictionary<string, string>> My inner dictionary has the following data { "1": { "message-Code1": " 0", "msg-Number-Pos11":...
Jon Skeet
people
quotationmark

Basically you should create new "inner" dictionaries. That's easy to do though: var replacedOuter = outerDictionary.ToDictionary( outerKey => outerKey, // Outer key stays the same outerValue => outerValue.ToDictionary( ... more 7/6/2017 7:01:12 AM

people

can not resolve symbol 'from' Error in Android Studio

can not resolve symbol 'from' in LayoutInflater inflater = new LayoutInflater.from(parent.getContext()); this is my complete class: package ir.sangram.sangram.chat; import...
Jon Skeet
people
quotationmark

You're calling LayoutInflater.from as if you were calling a constructor: LayoutInflater inflater = new LayoutInflater.from(parent.getContext()); That's a mixture of constructor-call syntax (new) and method call syntax (.from). It would... more 7/6/2017 6:47:27 AM

people

Get a list of duplicates from list based on properties comparison

I have a List<Demo> public class Demo { public Demo() { } public int Id { get; set; } public string Name { get; set; } public string Title { get;...
Jon Skeet
people
quotationmark

It sounds like all you're missing is a SelectMany call. Currently you're creating all the appropriate groups and filtering down to groups with more than one entry - but if you want a single flat list, you need to flatten those groups back... more 7/6/2017 6:44:29 AM

people