DEV Community

Nikas Belogolov
Nikas Belogolov

Posted on

2 1

Compile C# to WebAssembly?

How can I compile C# to WebAssembly (simple functions to calculate things) and run it in the browser?

Top comments (2)

Collapse
 
devarjunan profile image
dev-arjunan

Hi, Take a look at below article for more information.

codewithmukesh.com/blog/getting-st...

Collapse
 
nikas-belogolov profile image
Nikas Belogolov • Edited

But how Blazor compile c# to WebAssembly? I want to take c# code that calculates things (Temperature, Weight) and compile it into WebAssembly, Then use that code with Node.js and Javascript app. See Wikipedia example: en.wikipedia.org/wiki/WebAssembly

code in C:

int factorial(int n) {
  if (n == 0)
    return 1;
  else
    return n * factorial(n-1);
}
Enter fullscreen mode Exit fullscreen mode

Same in WebAssembly:

(func (param i64) (result i64)
  local.get 0
  i64.eqz
  if (result i64)
      i64.const 1
  else
      local.get 0
      local.get 0
      i64.const 1
      i64.sub
      call 0
      i64.mul
  end)
Enter fullscreen mode Exit fullscreen mode
👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay