You searched for how does c# work. We found 81 results in 0.252 seconds.

Alternative way convert int ? to double?

Is there any way to convert this ? public int? intVal ; public double? dblVal ; How I am working now if(dblVal==null) intVal =null; else intVal =...
Jon Skeet
people
quotationmark

Just cast: intVal = (int?) dblVal; This will already result in a null value if dblVal is null. Note that unlike Convert.ToInt32(double), this does not result in an exception if dblVal is outside the range of int. If that's a concern,... more

people

Why is the parameter is not updated?

I have a class that uses another class. The first class have this method: public void myMethod() { //Parameters are an enumeration. // Really is a exchange variable...
Jon Skeet
people
quotationmark

However, when in the clickButton I change the value of the _myParameters, is not changed in the object that was passed as parameter in the constructor of MyClass2. No, it wouldn't be. The value was passed in by value - the two... more

people

Foreach and Linq Statement Equalization

According to Resharper this two shall do the same: 1) string strTemp = null; foreach (var s in array) { if (strTemp == null || !strTemp.Contains(s)) { strTemp +=...
Jon Skeet
people
quotationmark

Judging by comments, you're expecting that this lambda expression will only be executed once, while strTemp still has a value of null. s => strTemp == null || !strTemp.Contains(s) That's not the case. It will execute for each element... more

people

Trying to understand method signature changes spanning assemblies

We ran into a strange problem with a promotion and I'm hoping I'll be able to explain it with code. I want to understand why it behaves in the manner it is. Assembly 1 public...
Jon Skeet
people
quotationmark

Why does the compiled code on assembly 2 change based on a method signature that (at least I think) should be transparent? No, it shouldn't. When you don't specify an argument to correspond with an optional parameter, the default... more

people

non Static Implicit Operator

Does anyone have an eloquent solution for the lack of support of non-static implicit operators in C#? The following codes shows my current problem: class Foo { ...
Jon Skeet
people
quotationmark

Fortunately, you can't do this. I say "fortunately" because it's very confusing for the reader. I suggest you just write a method instead, e.g. MergeFrom, so that you're code then reads: // Object initializers used for readability. Foo... more

people

Java executes arithmetic Expression wrong?

I don`t understand how Java is progressing this arithmetic expression int x = 1; int y = 1; x += y += x += y; System.out.println("x=" + x + " y=" + y); With Java I get x = 4...
Jon Skeet
people
quotationmark

This is the nasty part, obviously: x += y += x += y; This is executed as: int originalX = x; // Used later x = x + y; // Right-most x += y y = y + x; // Result of "x += y" is the value stored in x x = originalX + y; // Result of "y +=... more

people

Static/Instance methods and extension questions

I'm new to C# and I began working on a project that needed a method added to a class in C#. I found myself re examining the differences between static and instance methods and...
Jon Skeet
people
quotationmark

Your two methods are extension methods, which are meant to look like instance methods when they're called. They can be called statically, but you need to supply the instance as the first argument, and specify the class which declares the... more

people

Decoding Base64urlUInt encoded value

What I am generally trying to do, is to validate an id_token value obtained from an OpenID Connect provider (e.g. Google). The token is signed with the RSA algorithm and the...
Jon Skeet
people
quotationmark

RFC 7515 defines base64url encoding like this: Base64 encoding using the URL- and filename-safe character set defined in Section 5 of RFC 4648, with all trailing '=' characters omitted (as permitted by Section 3.2) and without the ... more

people

Awaiting custom functions

I'm trying to get my head around the new async features in C#, and so far the strangest thing I've noticed is that every example for async features has a function that awaits...
Jon Skeet
people
quotationmark

You're not starting the task - so it will never finish. Use Task.Run instead of new Task and it will create and start the task for you. Note that you're still reading the file synchronously, which isn't ideal... and if your Subject... more

people

Incorrect timezone from server side to Javascript

I have this method in the C# (server) side: protected double GetAccountTime() { return ((DateTime)unit.SomeMethod(DateTime.UtcNow)) .Subtract(new DateTime(1970,...
Jon Skeet
people
quotationmark

A Date object doesn't have any concept of a time zone. It always represents a number of milliseconds since the Unix epoch. You don't need to do any conversions - you've got the right point in time. (Indeed, there's no sense in which you... more

people