Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
Pass a slice of custom type from Go to C#

I am trying to integrate a Go application inside a large C# project. By using CGO it is easy to export functions from Go to C#, especially when the Go function return a generic type.

However, I have the need to call a Go function which return a slice of custom type from C#, possibly casting the slice to a C# list or array.

The Go function look like this

func Myfunc(n []int, m float64) []Res{...}

where type Res is

type Res struct {
    w IW
    p []Prs
    ti int64
    ms   int64
}

type Prs struct {
    mmz float64
    cge    int
    itntn int64
}

type IW struct {
    ledg float64
    redg float64
}

I could not find any documentation or example on the web, can I do this somehow?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I don't know how C# invoke Go, let's assume we are going to invoke Go function from C code.

  1. You need define Res struct in C file. like cgo_interface.h

  2. Then you write a cgo file like this:

package cinvokego

/*
#cgo CFLAGS: -I ${include}
#cgo LDFLAGS: -L ${libs}
#include "cgo_interface.h"
*/
import "C"

func GoFuncs(retArr *unsafe.Pointer, otherargs int) {
    // allocate memory and fill the retArr in here
}
  1. Then use go build --buildmode=c-archive cinvokego.go

  2. Then you will get header file and archive file generated by go build.

  3. Then you use header and archive like normal C resource.

  4. Then use C# to invoke C resource.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda