Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. where to include new class in c# , windows forms, visual studio

where to include new class in c# , windows forms, visual studio

Scheduled Pinned Locked Moved Managed C++/CLI
csharphelpvisual-studiowinformsdebugging
4 Posts 3 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 14124661
    wrote on last edited by
    #1

    Hi, I am working on some examples of my own and now looking to include a new class for my Banking transactions. Seems like I am doing something in the wrong place etc. I typed in the new code ahead of the standard code created by Visual Studio (17) (I didn't add an item). The information I wanted to create appears in the right hand window CLASS VIEW but I get the errors.

    using System.Windows.Forms;
    public class transactiondata
    {
    public DateTime transDT;
    public string transtext;
    public double transRECD;
    public double transPAID;
    public string transFlag;
    }
    //parameterised Constructor
    public transactiondata(DateTime transDT, string transtext, double transRECD, double transPAID, string transFlag)
    {
    this.transDT = transDT;
    this.transtext = transtext;
    this.transRECD = transRECD;
    this.transPAID = transPAID;
    this.transFlag = transFlag;
    return;
    }
    namespace Santander01
    {
    public partial class Form1 : Form
    {
    public Form1()

    CLASS VIEW shows the class and items above THE ERROR 1>------ Build started: Project: Santander01, Configuration: Debug Any CPU ------ 1>C:\Users\HOME\Documents\Visual Studio 2017\Projects\Santander01\Santander01\Form1.cs(19,8,19,23): error CS0116: A namespace cannot directly contain members such as fields or methods 1>C:\Users\HOME\Documents\Visual Studio 2017\Projects\Santander01\Santander01\For Any help appreciated

    L Richard DeemingR 2 Replies Last reply
    0
    • M Member 14124661

      Hi, I am working on some examples of my own and now looking to include a new class for my Banking transactions. Seems like I am doing something in the wrong place etc. I typed in the new code ahead of the standard code created by Visual Studio (17) (I didn't add an item). The information I wanted to create appears in the right hand window CLASS VIEW but I get the errors.

      using System.Windows.Forms;
      public class transactiondata
      {
      public DateTime transDT;
      public string transtext;
      public double transRECD;
      public double transPAID;
      public string transFlag;
      }
      //parameterised Constructor
      public transactiondata(DateTime transDT, string transtext, double transRECD, double transPAID, string transFlag)
      {
      this.transDT = transDT;
      this.transtext = transtext;
      this.transRECD = transRECD;
      this.transPAID = transPAID;
      this.transFlag = transFlag;
      return;
      }
      namespace Santander01
      {
      public partial class Form1 : Form
      {
      public Form1()

      CLASS VIEW shows the class and items above THE ERROR 1>------ Build started: Project: Santander01, Configuration: Debug Any CPU ------ 1>C:\Users\HOME\Documents\Visual Studio 2017\Projects\Santander01\Santander01\Form1.cs(19,8,19,23): error CS0116: A namespace cannot directly contain members such as fields or methods 1>C:\Users\HOME\Documents\Visual Studio 2017\Projects\Santander01\Santander01\For Any help appreciated

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You have terminated the class definition too early; the constructor is not inside it. Move the closing brace from where it is now, to the line following the end of the constructor block.

      1 Reply Last reply
      0
      • M Member 14124661

        Hi, I am working on some examples of my own and now looking to include a new class for my Banking transactions. Seems like I am doing something in the wrong place etc. I typed in the new code ahead of the standard code created by Visual Studio (17) (I didn't add an item). The information I wanted to create appears in the right hand window CLASS VIEW but I get the errors.

        using System.Windows.Forms;
        public class transactiondata
        {
        public DateTime transDT;
        public string transtext;
        public double transRECD;
        public double transPAID;
        public string transFlag;
        }
        //parameterised Constructor
        public transactiondata(DateTime transDT, string transtext, double transRECD, double transPAID, string transFlag)
        {
        this.transDT = transDT;
        this.transtext = transtext;
        this.transRECD = transRECD;
        this.transPAID = transPAID;
        this.transFlag = transFlag;
        return;
        }
        namespace Santander01
        {
        public partial class Form1 : Form
        {
        public Form1()

        CLASS VIEW shows the class and items above THE ERROR 1>------ Build started: Project: Santander01, Configuration: Debug Any CPU ------ 1>C:\Users\HOME\Documents\Visual Studio 2017\Projects\Santander01\Santander01\Form1.cs(19,8,19,23): error CS0116: A namespace cannot directly contain members such as fields or methods 1>C:\Users\HOME\Documents\Visual Studio 2017\Projects\Santander01\Santander01\For Any help appreciated

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        C# questions should be posted in the C# forum[^]. You've posted this in the "Managed C++/CLI" forum, which is nothing to do with C#. :)


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        L 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          C# questions should be posted in the C# forum[^]. You've posted this in the "Managed C++/CLI" forum, which is nothing to do with C#. :)


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Maybe he though that in the CodeProject numbering system, C++/CLI = C#. ;)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups