Browsing 7239 questions and answers with Jon Skeet

How to solve "The type or namespace name 'Systems' does not exist in the namespace 'Fizzler'"?

So I used Nuget to get the Fizzler package and it brought down the HTML agility pack, but now I have a compilation error when trying to use the library The type or namespace name...
Jon Skeet
people
quotationmark

Despite your comment, it looks like you need the Fizzler.System.HtmlAgilityPack package. You should then be able to use: using Fizzler.System.HtmlAgilityPack; ... at which point the extension methods in HtmlNodeSelection (including... more 12/29/2016 6:47:12 PM

people

c# restrict methods to other methods

I have a class that contains several methods eg.: class mySqlTool{ private string _values, _table, _condition, _result; public mySqlTool Select(string values = null){ ...
Jon Skeet
people
quotationmark

General description - see end for specific comments Is this what I want even possible? Not within the same class, no. How would the compiler know what you'd already called? (Imagine you had a method with a parameter of type Test -... more 12/29/2016 11:38:12 AM

people

how to fix the error on the Round, what should i change the line to?

public void ChangeTexts(long length, int position, int percent, double speed) { Label3.Text = "File Size: " + Math.Round((length / 1024), 2) + "...
Jon Skeet
people
quotationmark

You're currently dividing by 1024 in integer arithmetic and then rounding the result. In other words, you're rounding something that's already an integer - not really useful. The simplest fix is to divide by 1024.0 instead, to make it... more 12/29/2016 10:47:49 AM

people

Reusing of survived local variable in each call. UB?

I'm new in C#. I encountered such code-example: namespace App1 { delegate int Sum(int number); class TestAnonymusMethod { static Sum m() { ...
Jon Skeet
people
quotationmark

Is it "undefined behavior"? No, it's well-defined behaviour - just not the behaviour you expect. Looks like it happens because of when scope of result is closed, its life time is undefined. Nope, the lifetime of result is... more 12/28/2016 12:05:57 PM

people

What is wrong in code to

It's making me little hard to understand the actual behavior in this scenario. What is actually happening to not executing the task when it should but later when SemaphoreSlim is...
Jon Skeet
people
quotationmark

The problem is your using statement. This is how things are happening: Create the semaphore Start tasks running in the background Dispose of the semaphore Tasks try to use the semaphore... but can't, because it's... more 12/28/2016 10:54:04 AM

people

C# for loop and post increment

I'm having a hard time understanding why the following loop prints 0 on each iteration. for (int i = 0, j = 0; i < 10; i++) { Console.WriteLine(j += j++); } Shouldn't...
Jon Skeet
people
quotationmark

Shouldn't the value of j increase after each iteration? Nope. Your loop body is somewhat equivalent to this: int tmp1 = j; // Evaluate LHS of += int tmp2 = j; // Result of j++ is the value *before* the increment j++; j = tmp1 +... more 12/26/2016 9:25:03 PM

people

How do i refer to an object inside a method that it has invoked?

I've created a class named Rational which stores two private ints (numer and denom). I am trying to create a method that returns a new Rational object that contains the reciprocal...
Jon Skeet
people
quotationmark

It's not clear what rat1 is meant to be in your reciprocal method... but the reason you can't just use this(...) is that these are methods, not constructors. It looks to me like you probably want: public Rational reciprocal() { return... more 12/26/2016 8:28:08 PM

people

C# User class. GetHashCode implementation

I have simple class only with public string properties. public class SimpleClass { public string Field1 {get; set;} public string Field2 {get; set;} public string...
Jon Skeet
people
quotationmark

The contract for GetHashCode requires (emphasis mine): The GetHashCode method for an object must consistently return the same hash code as long as there is no modification to the object state that determines the return value of the... more 12/24/2016 11:44:49 AM

people

Accessing GenericTypeParameters of generic type in C#

I want to generate the name of the generic class with their declared parameter names. For example if I have generic class and instantiated ones like shown below I want to print...
Jon Skeet
people
quotationmark

I think you're just looking for Type.GetGenericArguments, which you should call on genericType rather than type - at that point, the type "arguments" are really the type parameters because it's an open type. Sample (using... more 12/23/2016 9:42:24 PM

people

How to remove single and double quotes at both ends of a string

I would like to remove single or double quotes from both ends of a string. The string may contain additional quotes or/and double quotes which shall remain untouched - so...
Jon Skeet
people
quotationmark

Option 1: Removing all single and double quotes from start and end You can use replaceAll which accepts a regular expression - replace doesn't - and do it twice, once for quotes at the start of the string and once for quotes at the... more 12/23/2016 8:59:40 AM

people