Browsing 7239 questions and answers with Jon Skeet

Is it possible to use Custom EventArgs with SystemEvents?

My first post, apologies if this has been answered already - I have searched and searched but have not found any specifics on using Custom EventArgs with existing SystemEvents. I...
Jon Skeet
people
quotationmark

No, you don't get to decide what parameters the event handler has. Bear in mind that there's already code in the system which is going to call your event handler... how would you expect it to construct an instance of your... more 4/9/2016 10:48:16 AM

people

multiple join on conditions sql to linq

how can i change the sql below to a linq. select distinct * from dbo.TbleA a left outer join dbo.TbleB b on a.schid = b.schid left outer join dbo.TbleC c on...
Jon Skeet
people
quotationmark

We can't really tell what's wrong with your current query in terms of compilation without knowing the types involved, but it wouldn't be equivalent to your original SQL anyway, as you want left outer joins. I suspect you want something... more 4/8/2016 2:57:12 PM

people

Extension fields in Kotlin

It's easy to write extension methods in Kotlin: class A { } class B { fun A.newFunction() { ... } } But is there some way to create extension variable? Like: class B { ...
Jon Skeet
people
quotationmark

No - the documentation explains this: Extensions do not actually modify classes they extend. By defining an extension, you do not insert new members into a class, but merely make new functions callable with the dot-notation on... more 4/8/2016 2:40:10 PM

people

What is this object initialiser pattern called?

I'm reviewing some code with an object initialisation pattern that I don't recognise - can anyone tell me what this pattern is called (and where to find documentation on...
Jon Skeet
people
quotationmark

It's just assigning the same value twice - once to myVar and once to myComplexType.myType. It's equivalent to var tmp = new MyType(); myVar = tmp; myComplexType.myType = tmp; (In some complex cases there can be type conversions going... more 4/8/2016 7:08:05 AM

people

Recursive replaceAll java

I am trying to replace all the repeated characters from a String in Java, and let only one. For example: aaaaa --- a For that, I have tried using the replaceAll...
Jon Skeet
people
quotationmark

Your replaceAll approach was nearly right - it's just that * matches 0 occurrences. You want + to mean "one or more". "aaaaa".replaceAll("a+","a") // Returns "a" more 4/7/2016 11:12:10 AM

people

Disadvantages of coding in C#6.0 but compiling against .NET 2.0

This question popped into my head today. C#6.0 or any other version for that matter all introduce cool new functionality making things easier to code. But lets say I have a...
Jon Skeet
people
quotationmark

Are they any downsides to writing my code in C#6.0 (or whatever the latest C# version is in the future) but compiling it against the .NET 2.0 framework (or some other version of .NET which is different than the C# version that it was... more 4/6/2016 2:44:26 PM

people

Is order guaranteed in an or expression

I have an expression like this: EqualByComparer comparer; if (ListEqualByComparer.TryGetOrCreate(x, y, out comparer) || EnumerableEqualByComparer.TryGetOrCreate(x, y, out...
Jon Skeet
people
quotationmark

Will ListEqualByComparer.TryGetOrCreate always be called before EnumerableEqualByComparer.TryGetOrCreate? Yes, and as || is short-circuiting, the second call will only be made if the first call returns false. From the C# 5... more 4/6/2016 10:13:57 AM

people

find a special node with its attribute from a XmlNodeList

I have an XmlNodeList that would like to find a special node inside it. I used the following code but I it does not find the desired node spite of it is in the...
Jon Skeet
people
quotationmark

As you've said you can use LINQ to XML, I'd use something like this: public List<XElement> FindElementsByName(XDocument doc, string name) { return doc.Descendants() .Where(x => (string) x.Attribute("name") ==... more 4/6/2016 9:14:18 AM

people

Java time zone with DST prints incorrect time (in negative epochs)

I'm having a hard time understanding the behavior of the following code: TimeZone zone = TimeZone.getTimeZone("Asia/Jerusalem"); DateFormat format =...
Jon Skeet
people
quotationmark

Let's just look at your 1915 example. The value -1712458800000 as millis-since-the-unix-epoch is 1915-09-26T21:00:00Z - in other words, exactly 9pm UTC. Now back in 1915, the UTC offset in Jerusalem was +2:20:40, which is why you see "Sep... more 4/6/2016 6:21:26 AM

people

c# index of array entries inside another array using LINQ

I have an array of strings: string[] stringArray = {"aaa", "bbb", "ccc", "aaa", "ccc", "ddd"}; I would like to get all indexes of this array where a substring of these strings...
Jon Skeet
people
quotationmark

Yup, you just need Any to see if "any" of the target strings are contained in the array element: List<int> index = stringArray .Select((Value, Index) => new { Value, Index }) .Where(pair => searchArray.Any(target =>... more 4/5/2016 9:11:16 PM

people