How to invoke a cs file in C#?

Posted on 2009-12-31
Last Modified: 2013-12-17
I have different modules for Business Layer, DataLayer, Business Entities layer.
Business Layer --> Contains cs files that contains the Business Logic
Business entities --> Contains cs files that contains attributes
Data Layer --> Contains the cs files that interacts with the DB. The results from this layer will be used to set the Entities attributes values in the Business Layer cs files
                         Now my requirement is, In the above existing modules{Solution}, I included a new set of independent files in each module. So, I have to invoke the file that I created in Business layer. I have to invoke a method inside the cs file by hardcoding the parameters. Please let me know on how can I implement this.
                         As in java, is there something called as main method in C#, so that I can diredtly execute the cs file, similar to java like, giving "java ClassName Parameters"
Question by:HelpSunny
    LVL 9

    Expert Comment

    In C#, you need to create a new project and put your main there. Then you can include your Business layer by adding reference to your project. This should be very easy for you if your middle layer is a class library project.
    Otherwise, you will need to write the csc command line by yourself, which is not integrated with Visual Studio and I dont recommend you to do that.
    LVL 11

    Expert Comment

    You can create class in DataLayer, Business Entities layer.
    Then call them by putting "using" keyword at the top of the cs file.
    LVL 2

    Accepted Solution

    The clean way to do this is to compile the cs file into an assembly, you get a reference to an instance of Assembly, and you can invoke methods by reflection.
    The assembly does not need to be saved as a file.

    Have a look at this example:

    This is a bit complex, but required if you don't know the contents of the cs files (eg. you ship the same binaries for several customers, and they have specific "plugins" implemented cs files)

    I'm not sure if this was the requirement, if not you'd better follow the suggestions above.

    Author Closing Comment

    Thank U

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now