---
title: "Calling C   function in .net."  
description: "Calling C   function in .net."  
author: "James Smith"  
published: 2011-04-16  
updated: 2011-04-16  
canonical: https://www.mindstick.com/forum/225/calling-c-function-in-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Calling C   function in .net.

Hello everyone,

Can [anyone tell me](https://www.mindstick.com/interview/23033/can-anyone-tell-me-about-hadoop-toolbox) that hot to call [c++](https://www.mindstick.com/blog/745/array-in-c-plus-plus) [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) in .net.

## Replies

### Reply by Anonymous User

Well I think that should not be to dificult. You can use DllImport statement to call any c++ dll library or function.

For example you have following c++ function in a dll.

```
int Sum(int x, int y){       return x+y;}
```

And you want to use this function in c# application.\
So you can useit like this.

```
using System;using System.Collections.Generic;using System.Text;using System.Runtime.InteropServices; //For "DllImport"namespace MyCSharp{      class Program      {      [DllImport("MathFuncsDll.dll", CharSet = CharSet.Auto)]      public static extern Int32 Sum(Int32 a, Int32 b);            static void Main()            {                  Console.WriteLine(Sum(3, 4));            }      }}
```


---

Original Source: https://www.mindstick.com/forum/225/calling-c-function-in-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
