Error while executing this code, displays on linux

Test begin... TestFunction, i = 0!!! 

Code:

 using System; namespace Callback { public class TestCallbacks { public Action<int, bool, decimal, decimal, bool> TestCallback; } public static class TestClass { public static TestCallbacks Callbacks; public static void Initialize(TestCallbacks callbacks) { Callbacks = callbacks; } public static void TestCallback() { // Passing i = 100! Callbacks.TestCallback(100, true, 200m, 300m, false); } } class Program { private static void TestFunction(int i, bool b1, decimal d1, decimal d2, bool b2) { Console.WriteLine($"TestFunction, i = {i}!!!"); } static void Main(string[] args) { Console.WriteLine("Test begin..."); var testCallbacks = new TestCallbacks() { TestCallback = TestFunction }; TestClass.Initialize(testCallbacks); TestClass.TestCallback(); } } } 
  • Which compiler (Mono, .NET Core) and which version are you using? - PetSerAl
  • @PetSerAl using .NET Core 2.0 - Barlukov
  • Can you specify the full version (preferably the SDK version)? There are more than one of them here. This page also reads "This release has reached the end of life, meaning it is no longer supported. We recommend moving to a supported release." perhaps should be updated to a more recent version. - PetSerAl
  • @PetSerAl dotnet --info .NET Command Line Tools (2.0.0) Product Information: Version: 2.0.0 Commit SHA-1 hash: cdcd1928c9 Runtime Environment: OS Name: centos OS Version: 7 OS Platform: Linux RID: centos. 7-x64 Base Path: /usr/share/dotnet/sdk/2.0.0/ Microsoft .NET Core Shared Framework Host Version: 2.0.0 - Barlukov
  • one
    Apparently some kind of runtime error 2.0.0 for Linux. If you run the build result in the latest version of .NET Core (2.2.1), then the program produces the correct result: i = 100 . - PetSerAl

1 answer 1

This is not true. I copied your code to ideone without changes: https://ideone.com/j2FlsU .

Here is the conclusion:

 Test begin... TestFunction, i = 100!!! 

And, of course, there is linux.

  • @PetSerAl, hmm .. The question is no .net-core tags, but generally yes, all of a sudden ... How so? - Qwertiy
  • Perhaps a bug in the old version of the compiler, considering that tio.run uses 2.3.2.61921. On my computer (not Linux), both C # compilers (Visual Studio 2017 and .NET Core) have version 2.10.0.0 and produce the expected result ( i = 100 ). - PetSerAl