# Convert between C# and Java with CSharpJavaMerger

**URL:** <https://forum.kirupa.com/t/convert-between-c-and-java-with-csharpjavamerger/297209>\
**Category:** programming\
**Created:** [September 28, 2009, 2:09am UTC](https://forum.kirupa.com/t/convert-between-c-and-java-with-csharpjavamerger/297209 "2009-09-28T02:09:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sindy55](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@sindy55](https://forum.kirupa.com/u/sindy55)\
**Post date:** [September 28, 2009, 2:09am UTC](https://forum.kirupa.com/t/convert-between-c-and-java-with-csharpjavamerger/297209/1 "2009-09-28T02:09:49Z")

</div>

CSharpJavaMerger is an open source tool. It provides common interfaces of C# and Java and enables you to write one set of code which can be used both by C# and Java.

Below is a method that can be used in both of C# and Java. In the sample, CString is a class defined in the CSharpJavaMerger Framework.

public void AddTwoValues()  
{  
try  
{  
CString strValue1 = m\_mainForm.GetFirstTextBoxValue();  
CString strValue2 = m\_mainForm.GetSecondTextBoxValue();

```
    int iValue1 = strValue1.ToInteger();
    int iValue2 = strValue2.ToInteger();
    int iResult = iValue1 + iValue2;
    CString strShowResult = CString.ValueOf(iResult);
    m_mainForm.ShowResult(strShowResult);
    CString strSaveResult = new CString(strValue1.GetValue() + " + " + strValue2.GetValue() + " = " + strShowResult.GetValue() + "

```

");  
m\_mainForm.SaveResult(strSaveResult);  
}  
catch (Exception ee)  
{  
m\_mainForm.SaveResult(new CString(ee.Message + "  
"));  
m\_mainForm.ShowResult(new CString(“Error”));  
}  
}

More info on CSharpJavaMerger: [http://www.kevingao.net/csharp-java-conversion](http://www.kevingao.net/csharp-java-conversion)
