Browsing 15836 questions and answers with Jon Skeet

Create library targeting .Net Framework 4.5 and .Net Standard

I have a .NET library (Products.SDK) which i need to make it compatible with both .NET Framework 4.5 and .NET Standard 1.4. (later on i will also create a NuGet package out of...
Jon Skeet
people
quotationmark

You use option two - but only use #if in places where you really need it. The example you gave had the same code in both branches. My Noda Time project takes exactly this approach, and we've had very few problems due to that. Where... more 8/22/2017 8:03:00 AM

people

why does params byte[] argument doesnt work?

i have this method from a pattern scanner public static int FindPFM(int Module,long ModuleL,int Offset,params byte[] pattern) { string mask =...
Jon Skeet
people
quotationmark

When you invoke a method with a parameter array, the arguments go at the end, not the beginning (to match the parameter array position). Next, the arguments don't go in parentheses as you've tried to do - that's the syntax for a C# 7 tuple... more 8/19/2017 8:48:36 PM

people

Dynamic Order By in Linq

I have an app that accesses database and has to order results by different fields depending on the input. Here is my function for sorting: IQueryable<Entity>...
Jon Skeet
people
quotationmark

Well, you definitely want to use OrderByDescending instead of reversing. It's not going to be quite as brief as the SQL, but you could at least use: IQueryable<Entity> GetSortedData(IQueryable<Entity> result, String orderby,... more 8/18/2017 4:44:41 PM

people

Generic functions and ref returns in C# 7.0

Is it possible to use the ref returns feature in C# 7.0 define a generic function that can do both comparison and update of a field in two instances of an Object? I am imagining...
Jon Skeet
people
quotationmark

You need to declare your own delegate type for it. For example: using System; public class Thing { public int field1; public string field2; } public delegate ref TOutput FuncRef<TInput, TOutput>(TInput input); public... more 8/18/2017 3:46:13 PM

people

Adding Count of Arrays Together returns 0

I have the following class, where the arrays are populated public class InternalTag_RelatedObjectsViewModel { public Guid[] BranchIDS { get; set; } public Guid[]...
Jon Skeet
people
quotationmark

You're missing precedence, basically. It's easier to see what's going on when this is reduced to a minimal example: using System; public class Program { public static void Main() { string[] a = { "x", "y" }; ... more 8/18/2017 10:45:11 AM

people

c# FileStream Read having problems with StreamReader EndOfStream

As the title says I found a problem. Little back story first: We have file.txt looking like this: aaaabb ccccddd eeeefffffff There are many ways to read this text line-by-line,...
Jon Skeet
people
quotationmark

Now there's a problem. Now arr doesn't get anything and s reads the whole line including the first 4 letters. Yes, that seems very plausible. StreamReader maintains a buffer - when you ask it to read a line of text, it may well read... more 8/18/2017 7:32:22 AM

people

Generate random boxed co ordinates in c#

I need to find random co-ordinates, bound like a square. For this I defined this where the values 70, 55, 175, 175 are the furthest points I want to go to: north =...
Jon Skeet
people
quotationmark

I would suggest you change your approach: Generate a point for the North/West corner, anywhere in the appropriate range Generate the width and height, ensuring they're positive Set East = West + Width, and South = North - Height more 8/18/2017 6:29:52 AM

people

prepare a set of arguments that can pass to a function in java

I want to call a function like private void passStrings(String... arg){} And I have an array which store a set of Strings but don't know its size. So How can I use all that array...
Jon Skeet
people
quotationmark

Just pass it as the array: String[] array = { "Some", "arguments", "I", "prepared", "earlier" }; passStrings(array); A varargs parameter like arg is still an array parameter really - it's just that the compiler allows you to specify the... more 8/18/2017 6:04:05 AM

people

The current .NET SDK does not support targeting .NET Standard 2.0 error in Visual Studio 2017 update 15.3

I want to create a class library project with Target Framework .NET Standard 2.0. I've updated my Visual Studio 2017 to Version 15.3 and also in Visual Studio installer checked...
Jon Skeet
people
quotationmark

It sounds like installing the VS2017 update didn't also install the .NET Core 2.0 SDK. You can download that here. To check which version of the SDK you've already got installed, run dotnet --info from the command line. Note that if... more 8/17/2017 2:22:58 PM

people

DateTime Manipulation in C# vs Java

I'm new to Java. I have a time I am getting from a web-page, this is in the "hh:mm" format (not 24 hour). This comes to me as a string. I then want to combine this string with...
Jon Skeet
people
quotationmark

Is there a better way to achieve what I want? Absolutely - in both .NET and in Java, in fact. In .NET I'd (in a biased way) recommend using Noda Time so you can represent just a time of day as a LocalTime, parsing precisely the... more 8/16/2017 12:27:05 PM

people