C class without main method

0 votes

I'm learning C# and am somewhat new to it, so please excuse my seemingly inane inquiry. I've worked with Java before, and I've noticed that C# projects likewise require a main() method in the main class.

What if I want to make a class that isn't a main class, but that I can import into one?

When I compile (through cmd using csc File.cs), the compiler complains that the.exe it would generate lacks a main() method. Is this to say that I was mistaken and that every class need a main() method, or that I'm compiling it incorrectly?

Perhaps the issue is in the code (as I'm relying on my Java syntactic expertise), which looks like this:

public class Class
{
    int stuff;
    public Class(int stuff)
    {
        this.stuff = stuff;
        stuff();
    }
    public void method()
    {
        stuff();
    }
}
Jun 11, 2022 in C# by jyoti
• 1,240 points
940 views

1 answer to this question.

0 votes
Not every single class need the main method. This is also confirmed in the MSDN documentation. Read this: https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/acy3edy3(v=vs.100)?redirectedfrom=MSDN

The Main method, which serves as the application's entry point, can be kept in just one class and these are the ways you can make that happen: static void Main(string[] args) or static void Main() or static int Main(string[] args) or static int Main()
answered Jul 7, 2022 by krishna
• 2,820 points

Related Questions In C#

0 votes
0 answers

How to force overriding a method in a descendant, without having an abstract base class

This is my code using System; using System.Collections.Generic; using System.Linq; using ...READ MORE

Jun 11, 2022 in C# by krishna
• 2,820 points
1,009 views
0 votes
1 answer

Correct syntax for main method

Both ways are correct. But taking the ...READ MORE

answered Jun 7, 2022 in C# by pranav
• 2,590 points
645 views
0 votes
1 answer

How can I compile and run c# program without using visual studio

If you have.NET Framework v4 installed, then C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe ...READ MORE

answered Jun 9, 2022 in C# by rajiv
• 1,620 points
1,311 views
0 votes
0 answers

Creating a generic method in C#

I'm attempting to integrate several comparable techniques ...READ MORE

Jun 11, 2022 in C# by pranav
• 2,590 points
562 views
0 votes
1 answer

no 'access-control-allow-origin' header is present on the requested resource

The java <class-name> command syntax is one ...READ MORE

answered Feb 8, 2022 in Java by Soham
• 9,710 points
786 views
0 votes
1 answer

SEO asp.net description spelling order

https://neilpatel.com/blog/simple-guide-to-seo/ here you can see step by ...READ MORE

answered Mar 1, 2022 in Digital Marketing by narikkadan
• 63,600 points
488 views
0 votes
1 answer

First C# program with two Classes. Confused

I figured out where your problem is Craps ...READ MORE

answered Jun 21, 2022 in C# by jyoti
• 1,240 points
437 views
0 votes
1 answer

OOP real world example

This is what I believe. OOP does not ...READ MORE

answered Jul 4, 2022 in C# by krishna
• 2,820 points
1,010 views
0 votes
1 answer

Pass Method as Parameter using C#

In .NET 3.5, you can utilize the ...READ MORE

answered Jun 14, 2022 in C# by krishna
• 2,820 points
967 views
0 votes
1 answer

What does the extension method do in c# and why do you need it

Extension Methods allow you to add additional ...READ MORE

answered Jun 21, 2022 in C# by krishna
• 2,820 points
659 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP