Browsing 7239 questions and answers with Jon Skeet

How to get input and return type of delegate stored in list<dynamic> in c#?

I want to create list of method. and run this list of method in order. The input of next method is output of current method. So, this is my code for these, and i need to get...
Jon Skeet
people
quotationmark

Yes, you can use foreach, and call Invoke dynamically - you'll need the input to be dynamic as well though: using System; using System.Collections.Generic; class Test { static void Main() { Func<int,int> fn1 = new... more 8/7/2017 7:12:29 AM

people

How to work around rank N polymorphism in C#?

Suppose there is an identity function, which is: T Id<T>(T t) { return t; } What should I type F? void F<T>(Func<T, T> f) { // This is not sound! ...
Jon Skeet
people
quotationmark

It's not clear to me what you're trying to achieve, but you could do this with a non-generic interface that contains a generic method: using System; interface IGenericSameTypeFunction { T Apply<T>(T input); } public class... more 8/6/2017 8:37:03 AM

people

Primitive type casting in java (disconcerting examples)

I've read most of the threads on this site concerning typecasting (please do not link me to any more or mark this as a duplicate), and would like an explanation on some of these...
Jon Skeet
people
quotationmark

The first two are handled by the same case - JLS section 5.2: In addition, if the expression is a constant expression (ยง15.28) of type byte, short, char, or int: A narrowing primitive conversion may be used if the type of the... more 8/6/2017 6:46:13 AM

people

Why AsEnumerable also execute filter on server

I'm using Linq to Entities in my program, and i have the following two simple queries: var result = dbContext.Customers.Where(c => c.Name == "Mostafa").ToList(); var result2 =...
Jon Skeet
people
quotationmark

AsEnumerable() makes the remainder of the query execute locally. Anything earlier than the AsEnumerable() is still part of the IQueryable execution flow. For example, think about this (imagining an Age property): var result =... more 8/5/2017 10:00:24 PM

people

C# ; expected in Throw New Excepction error using Assert

Im using this code in C# project public async Task should_not_raise_exception(Mock<IWebSocketClient> webSocket, SlackConnection slackConnection) { // given ...
Jon Skeet
people
quotationmark

You can reproduce the problem with just this line of code: Action<string> foo = message => throw new Exception(); The problem is that before C# 7.0, you couldn't use throw as an expression on its own... and that's what an... more 8/5/2017 9:00:35 PM

people

Creating a table within a dataset in BigQuery programmatically

Is it possible to create a table within a dataset in BigQuery using the API in Java? I know it's possible with bq mk --schema <fileName> -t...
Jon Skeet
people
quotationmark

I haven't used the Java BigQuery library personally1, but it looks like you should call BigQuery.create(TableInfo, TableOptions[]. That documentation has this example code - assuming you already have an instance of a BigQuery interface... more 8/5/2017 8:19:59 PM

people

Convert.ToDouble in c# not giving right answer when accessing redis database

Im trying to convert a long string of numbers into a double in order to use that as an index to a redis database (redis requires a double) but the conversion isnt correct so the...
Jon Skeet
people
quotationmark

I cant understand why, its a WHOLE NUMBER, no fractional part to create error so why it cant do it? Because it still only has 64 bits of information to play with, 52 of which are used for the mantissa, 11 of which are used for the... more 8/5/2017 7:21:02 PM

people

Hashmap Key: String, Value: Boolean. How do I test the value within an if statement?

/ public void getFinishedBooks(HashMap<String, Boolean> library) { if (library.size() < 1) { System.out.println("No books in Library"); } else { for (String books...
Jon Skeet
people
quotationmark

Rather than getting the key set, I'd get the entry set - that means you can iterate over the key/value pairs, rather than having to look up each key again. For example, to print all the books with a true value: for (Map.Entry<String,... more 8/5/2017 5:15:49 PM

people

Create delegate with reference to method in DLL

I have DLL with some methods. I load it in runtime and I want to create delegate to method that is located in DLL. DLL: public static Point Play(int[,] foo, int bar, int baz) {...
Jon Skeet
people
quotationmark

You'd need to find the type containing the method first, then use Delegate.CreateDelegate: Type type = ass.GetType("NameOfTypeContainingMethod"); PlayDel del = (PlayDel) Delegate.CreateDelegate(typeof(PlayDel), type,... more 8/5/2017 5:12:29 PM

people

Changing System Date and Time Using DateTimePicker via C#?

I'm trying to change the time but when I try to change the time to 00:00 it becomes 08:00 instead? Is it considering my timezone which is UTC + 8? using System; using...
Jon Skeet
people
quotationmark

Yes, it's precisely because of the time zone issue. From the docs for SetSystemTime: Sets the current system time and date. The system time is expressed in Coordinated Universal Time (UTC). So if you're trying to change it to a... more 8/5/2017 1:30:32 PM

people