c# method not returning string to python
Question: I am trying to call c# code from python using ctypes module. The problem is c#
method returning integer value properly but not doing so for string. It
returns different numbers instead of string. The number also varies each time
it runs. Can anyone please tell what is the problem with this code. My python
code is given below:

Python Code:

    
    
    import ctypes
    a = ctypes.cdll.LoadLibrary(r"C:\path\ConsoleApplication1.dll")
    print a.mul(10,4)
    print a.add(10,4)
    print a.str()
    

C# code:

    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;
    using RGiesecke.DllExport;
    
    
    class Test
       {
       [DllExport("TestExport", CallingConvention = CallingConvention.Cdecl)]
       public static int add(int left, int right)
          {
            return left + right;
          }
       [DllExport("mul", CallingConvention = CallingConvention.Cdecl)]
       public static int mul(int left, int right)
          {
            return left * right;
          }
       [DllExport("str", CallingConvention = CallingConvention.Cdecl)]
       public static String str()
         {
           String var = "hello";
           return var;
    
          }
    
       }
    


Answer: Change following code

    
    
     [DllExport("str", CallingConvention = CallingConvention.Cdecl)]
      public static String str()
     {
       String var = "hello";
       return var;
    
      }
    

to

    
    
     [DllExport("str", CallingConvention = CallingConvention.Cdecl)]
    public static String str()
     {
       String str= "hello";
       return str;
    
      }
    

`var` is keyword in `c#` and cannot be used as variable name

