Jul 15 2009

An example

Published by at 10:13 pm under General

This CSharpJavaMerger Framework is the work of Dr. Hongying Gu. Duplicated and adapted with her permission.

This article is a part of CSharpJavaMerger Framework, an open source project. Join us now to make it better!

Below is a piece of code of a method. In the sample, CString, a class defined in the CSharpJavaMerger Framework, is used instead of String. This way, the method AddTwoValues can be used in both C# and Java.

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() + "\n");
m_mainForm.SaveResult(strSaveResult);
}
catch (Exception ee)
{
m_mainForm.SaveResult(new CString(ee.Message + "\n"));
m_mainForm.ShowResult(new CString("Error"));
}
}

Links:
Previous article >>>>: Architecture
Next article >>>>: How to write C# code?
WCF & Java Interop series home page: CSharpJavaMerger Framework

No responses yet

Trackback URI | Comments RSS

Leave a Reply