Hw do I set static mesh through code?

There is my code:

WeaponMesh = CreateDefaultSubobject(TEXT(“WEAPON”));
WeaponMesh->SetupAttachment(GetCapsuleComponent());
WeaponMesh->RelativeLocation = FVector(60.f, 23.f, -21.f);
static ConstructorHelpers::FObjectFinderMeshAsset(TEXT(“StaticMesh’/Game/shotgun.shotgun’”));
UStaticMesh* WeaponAsset = MeshAsset.Object;
WeaponMesh->SetStaticMesh(WeaponAsset);

Any help would be appreciated.

// Hi, this should work. Copy and paste below into your constructor. Hope it helps.

/** Your header file should look like this */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Weapon")
class UStaticMeshComponent* WeaponMesh;

/** include these headers in your cpp file */

#include "Components/StaticMeshComponent.h"
#include "UObject/ConstructorHelpers.h"
#include "Engine/StaticMesh.h"

/** Add this to your default constructor in cpp file */

// set the mesh
WeaponMesh = CreateDefaultSubobject(TEXT("WEAPON"));
// attach to root component
WeaponMesh->SetupAttachment(GetRootComponent());

// set path for static mesh. Check path of mesh in content browser.
static ConstructorHelpers::FObjectFinder Shotgun(TEXT("StaticMesh'/Game/shotgun.shotgun'"));

// check if path is valid. Check path of mesh in content browser.
if (Shotgun.Succeeded())
{
       // mesh = valid path
	WeaponMesh->SetStaticMesh(Shotgun.Object);
       // set relative location of mesh
        WeaponMesh->SetRelativeLocation(FVector(60.f, 23.f, -21.f));
}

Thanks. Can you please show me how to do it with an input?