7

I have some useful code written in C# and I want to use it in my android app. Can I use it directly, or it is nesessary to rewrite it on Java?

TpoM6oH
  • 8,385
  • 3
  • 40
  • 72

6 Answers6

9

You will need to rewrite it. Or Run your C# code as a web service (WCF or Web API) and have your java application talk to the web service

twaldron
  • 2,722
  • 7
  • 40
  • 55
5

There's a project called Mono for Android, and it gives you the ability to write android apps in C#:

http://xamarin.com/monoforandroid

Dave Zych
  • 21,581
  • 7
  • 51
  • 66
  • 1
    As I understand it is possible to write the whole project using c# and mono, but I can't find is it possible to use just a bunch of C# code in a java app. – TpoM6oH Oct 10 '12 at 14:31
  • @user1735198 if that's the case, you can go with twaldron's answer. – Eng.Fouad Oct 10 '12 at 14:33
  • @user1735198 - If it wasn't possible to use C# within a Java application then `Mono for Android` wouldn't be possible. – Security Hound Oct 10 '12 at 15:06
4

If you are looking to do it for free, you probably have to just rewrite it in Java.

toadzky
  • 3,806
  • 1
  • 15
  • 26
1

You are looking for Mono for Android~

enter image description here

Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
1

If you are looking to mix C# and Java, then it will probably be more trouble than it is worth. However using Mono for Android and reading this similar question you can find the Droid you are looking for.

Community
  • 1
  • 1
Austin Henley
  • 4,625
  • 13
  • 45
  • 80
1

Depending on how many lines of code you are talking about, I would start with one of the size limited demo versions of the several 'csharp to java' code converters available. Google 'csharp to java'. You won't necessarily get perfect, runnable, java code but it will break the back of the conversion exercise for you.

paulkayuk
  • 1,052
  • 1
  • 8
  • 15