Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Articles by Jon Skeet
Mastering C# Fundamentals: Book Management Application File Handling for Saving and Loading Data
In this article, we will complete our book management application by adding file handling features to save book information to a file and load it again when needed. This addition will make our application far more practical, allowing it to persist data across different runs. We will continue to use the System.IO namespace, focusing on writing and reading text files using classes such as File, StringBuilder, and StreamReader.
Closed as unhelpful: an elegy for Stack Overflow
I posted my very-first-ever StackOverflow question on the second day of my first job after college. I really wanted to link the post here, but it was so long ago that I can’t find the question, or even the throwaway account I was using at the time. I think it was something about talking to SQL Server with PowerShell. I do remember that I felt nervous, overwhelmed, out of my depth in my new job. I was too embarrassed to ask a coworker for help.
SEO for Non-Scumbags: How to Earn Site Visitors without Selling Your Soul
Editorial note: hi folks! Thanks for your patience as I’ve been getting my life settled enough to start creating content again. We’ve done some hiring for a few roles, backfilling me, so I’m actually seeing a light at the end of the tunnel for creating DaedTech content. Today I’m going to start a blog post series that fits into the broader “business of freelancing” category.
Software Mistakes and Tradeoffs
Look inside Preparing to Work with Date/Time Information ch 1 audio You browser does not support the audio element.
What are the application implications of a netstandard library depending on a metapackage?
You shouldn't need to disable the implicit reference. All platforms that the library will be able to run on will already have the assemblies that the dependency would require. The .NET Standard Library is a specification, a set of reference assemblies that you compile against that provides a set of APIs that are guaranteed to exist on a know set of platforms and versions of platforms, such as .NET Core or the .NET Framework.
Core .NET - Dzone Refcardz
One common task which always has me reaching for MSDN is working out how to format numbers, dates and times as strings. There are two ways of formatting in .NET: you can call ToString directly on the item you wish to format, passing in just a format string or you can use composite formatting with a call to String.Format to format more than one item at a time, or mix data and other text.
Anonymous classes and LINQ select query
Anonymous class has read only properties in c#. Which is often used to to declare in linq select query to get particular values from database. In my code I have the following query.The thing that confused me selecting new object of anonymous class using new statement. I had a model class of . When I Use model name the query result allow editing. When I did not mention type after in statement I am unable to exit. compiler raise an error . enonymous object is read only.
Java8 method reference used as Function object to combine functions
You should be able to achieve what you want inline by using casts: Stream.of("ciao", "hola", "hello") .map(((Function<String, Integer>) String::length).andThen(n -> n * 2)) There are only 'type hints' for the compiler, so they don't actually 'cast' the object and don't have the overhead of an actual cast.
What is the difference between a variable, object and a reference?
I like to use an analogy of telling someone where I live. I might write my address on a piece of paper: A variable is like a piece of paper. It holds a value, but it isn't the value in itself. You can cross out whatever's there and write something else instead. The address that I write on the piece of paper is like a reference. It isn't my house, but it's a way of navigating to my house. My house itself is like an object.
List.Any get matched String
Any determines only if there is a match, it doesn't return anything apart from the bool and it needs to execute the query.
roslyn failed to compile code
Looks like a compiler bug to me. Although the and expressions are evaluated dynamically, I would expect the compiler to still understand that by the time it reaches , both and are definitely assigned. Even with the weirdnesses you can come up with in dynamic typing, I'd expect to only ever evaluate after evaluating both of the calls. No, but there are workarounds.
Why is this cast redundant?
Because the overload with the parameter is "better" than the overload with the parameter... because the conversion from to is "better" than the conversion from to . is more specific than , because there's an implicit conversion from to , but not vice versa. If the final parameter for the first method were instead (for example) then neither overload would be better than the other, and the call would be ambiguous without the cast.
c# 4.0 - Can "this" be null in C# virtual methods? What happens with the rest of instance methods? - Stack Overflow
Not possible directly in C# code (unless you generate dynamic code with Reflection.Emit or similar techniques) but by using directly IL code it is possible to call a virtual method and having the . save it to .
The Workplace Stack Exchange
No. Other's have covered those reasons admirably. You didn't ask this question, but I think it's the more relevant one. In general I'd say proceed with caution. If your recent question history on SO is such that it paints you in a very bad light then you probably don't want to highlight this. For example if you are applying for a MS SQL DBA job and last month you asked how to create a trigger - that would be bad.
Why do we assign child class object to parent class reference variable?
I have the following code. public class Parent { public void Print() { Console.WriteLine ("Parent Method"); } } public class Child : Parent { public new void Print() { Console.WriteLine ("Child Method"); } } public class Program { public static void Main() { Child C = new Child(); C.Print(); } } If I run this code, I get the result "Child Method" But if I do the following, why do I get the result "Parent Method"?
Strange implementation of Object.Equals
Basically, this would only be of any use to developers with flawed implementations. From the documentation: The following statements must be true for all implementations of the method. In the list, , , and represent object references that are not null. returns the same value as . So the check is redundant in every case where the method has been correctly implemented - causing a performance hit to every developer who has done the right thing.
Strange behavior of Enumerator.MoveNext()
returns a mutable value type ( ). You're storing that value in the anonymous type. Now, let's have a look at what this does: Now note what we're calling on - the copy of the value which is in the anonymous type. You can't actually change the value in the anonymous type - all you've got is a property you can call, which will give you a copy of the value. If you change the code to: ... then you'll end up getting a reference in the anonymous type. A reference to a box containing the mutable value.
What makes the Visual Studio debugger stop evaluating a ToString override?
Recently, I've been debugging some of my Noda Time code, and I've noticed that when I've got a local variable of type (one of the central types in Noda Time), the "Locals" and "Watch" windows don't appear to call its override. If I call explicitly in the watch window, I see the appropriate representation, but otherwise I just see: which isn't very useful.
Operation to "Get and AND" boolean variable in Java
I've been struggling to see why the OP is trying to use bool &= false; when bool = false will obviously do. In that sense, Jon Skeet's answer is (unsurprisingly) correct. What I think the OP actually wants to do is set the variable to false and test it in one step. That's the reason for the reference to AtomicBoolean. It's nothing per-se to do with loops. IE he wants to do the same as: int a=0; for ( ... ) { if (a++ == 0 ) { // works if we aren't doing too many iterations continue; } ...
"Get and AND" in Java
Personally I would simplify your current code to: for (...) { if (bool) { bool = false; continue; } } ... but if you really want to do it in the if condition as a side-effect, you could use: for (...) { if (bool && !(bool = false)) { continue; } } Here the first operand of the && operator covers subsequent operations, and !(bool = false) will always evaluate to true and set bool to false. I really, really wouldn't use that code though.
GitHub for Windows does not see changes in repository
I have created a repository using GitHub for Windows (GfW) and added 3 commits and synced using aforementioned. Commits were visible on GitHub webpage and in my app. Then my brother forked my project to start collaborating with me. He successfully cloned it using GfW. Then i made changes on my machine and pushed using "sync" button. Changes appeared on webpage and in my history, but my brother can't see them in his GfW. Even after pressing "sync". What mistake are we making?
Overloading method on extended class
Because the compile-time type of is . Overloading is performed at compile-time... the execution-time type of the object you call the method on is only relevant for overriding. So the compiler is choosing the method as that's the only method it's aware it can call on (and it's checked that it's applicable given the argument list). That method isn't overridden in , therefore at execution time, the implmenetation in is called.
In C#, why doesn't ?: operator work with lambda or method groups?
Anonymous functions and method groups don't have types in themselves - they are merely convertible to delegate types (and expression tree types for some lambda expressions). For the conditional operator to determine the overall type of the expression, at least one of the second or third operands has to have a type. You could cast either of them to Func<string, byte[]> and the compiler would find that it could convert the other one to the same type, and be happy.
Does string interpolation evaluate duplicated usage?
Most of the time, the compiler will be able to optimize this. Unfortunately, the times it can't are also the times you would care most. Optimization in this context is not based on calling the same function twice, but based on inlining. Accessors usually are trivial (looking up a field, or at most doing a conversion between numeric types or format/parse between numeric and string type) and as such, easily meet the criteria for inlining.
Why does Java prefer to call double constructor?
Both constructors are applicable, because is convertible to both and - so the compiler needs to use overload resolution to determine which constructor to call.
Why java prefers to call double constructor
Both constructors are applicable, because is convertible to both and - so the compiler needs to use overload resolution to determine which constructor to call.
Why do two programs have forward referencing errors while the third does not?
This is covered by section 8.3.3 of the JLS: Use of class variables whose declarations appear textually after the use is sometimes restricted, even though these class variables are in scope (§6.3).
Is it possible to store functions in a dictionary?
It sounds like you probably want something like: Dictionary<string, Func<string[], int>> functions = ...; This is assuming the function returns an int (you haven't specified). So you'd call it like this: int result = functions[name](parameters); Or to validate the name: Func<string[], int> function; if (functions.TryGetValue(name, out function)) { int result = function(parameters); ...
Thread safety in String class
Both and as parameters in this method are effectively immutable and cannot be changed by outside code. So there is no need to care about thread-safety with either Format method or String.Concat in this case.
Has anyone tried to estimate Stack Overflow users skill by analyzing the data dumps?
Yes, this has been done in a recently released StackApp called StackRating. Each question was seen as a "game", the responders were seen as "players" and the outcome of each game was determined by the votes. The ratings of each player was tracked using the Elo rating system. In a nutshell it worked as follows: If you answer a question and get 20 upvotes, and I answer the same question and get 2 upvotes, then you have "won" and I have "lost".
OOPS Inheritence and default constructor
Suppose there is a base class A. And there is another class B derived from A. Then, we know that the constructor of class A is never inherited by class B. However, when a new object of B is created, then, the default constructor of the class A is called prior to the default/custom constructor of class B is invoked. Maybe the purpose of this is that the fields of class A need to be initialized to default values...
Use of Java static modifier and static block
In this example, there's one subtle difference - in your first example, isn't determined to be a compile-time constant, so it can't be used as a case in blocks (and wouldn't be inlined into other code); in your second example it, is. So for example: That's valid when is deemed to be a constant expression, but not when it's "just" a static final variable. However, static initializer blocks are usually used when you have more complicated initialization code - such as populating a collection.
Difference between static modifier and static block
In this example, there's one subtle difference - in your first example, isn't determined to be a compile-time constant, so it can't be used as a case in blocks (and wouldn't be inlined into other code); in your second example it, is. So for example: That's valid when is deemed to be a constant expression, but not when it's "just" a static final variable. However, static initializer blocks are usually used when you have more complicated initialization code - such as populating a collection.
Why does this if statement, with an assignment and equality check, evaluate to false?
This is a precedence issue, basically. You're assuming that your code is equivalent to: if ((test1 = false) || (test1 == false)) ... but it's not. It's actually equivalent to: if (test1 = (false || test1 == false)) ... which is equivalent to: if (test1 = (false || false)) (because test1 is true to start with) ... which is equivalent to: if (test1 = false) which assigns the value false to test1, with the result of the expression being false.
how java if work when assignment and equals is there with or operation
This is a precedence issue, basically. You're assuming that your code is equivalent to: if ((test1 = false) || (test1 == false)) ... but it's not. It's actually equivalent to: if (test1 = (false || test1 == false)) ... which is equivalent to: if (test1 = (false || false)) (because test1 is true to start with) ... which is equivalent to: if (test1 = false) which assigns the value false to test1, with the result of the expression being false.
C# anonymous object with properties from dictionary
It isn't an anonymous object but you can accomplish this with a DynamicObject! You could do the following.
interop - In C# bool is 4-byte size? Isn't that too much? - Stack Overflow
The bool type has a checkered history with many incompatible choices between language runtimes. This started with an historical design-choice made by Dennis Ritchie, the guy that invented the C language. It did not have a bool type, the alternative was int where a value of 0 represents false and any other value was considered true. This choice was carried forward in the Winapi, the primary reason to use pinvoke, it has a typedef for which is an alias for the C compiler's int keyword.
ORTC and the Future of WebRTC
The first stable ORTC (Object RTC) specification is out. The questions is how is it going to impact WebRTC? Back in 2013, Robin Raymond, Chief Architect at Hookflash, has expressed his discontent with the use of SDP (Session Description Protocol) in WebRTC.
Call method from a parent class and use child class properties
Firstly, I'd suggest avoiding using public fields - use properties if you want to make state public. (You're asking for a property in your reflection call, but your derived class declares a field...) At that point, you can make an abstract property in the base class, and allow each derived class to implement it however they want - but you can still call it from the base class.
java, integer isn't used (calculator)
I am busy making a calculator but somehow the integer isn't used, I don't know why. I try to fix it but I can't find out how to do it. I use a button with a event to calculate the answer, maybe something's wrong with that.
Show More
loading
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with Jon
Contact Jon, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack