I just want to ask, can I use private classes in a console application without putting properties in it ?

like this for example:

class sample1
  {
       static void main()
           {
                private int multiply()
            {
               Console.WriteLine("hello");

                
            }
           }

   }

Recommended Answers

There is no private class and any sign of any property in your example. Private class does not exist at all (it cannnot).
Do you know what properties are? And what classes are for?

Jump to Post

You cannot declare other methods inside a method in a C-like language.

You can in C# :) Anonymous methods.

Jump to Post

All 7 Replies

There is no private class and any sign of any property in your example. Private class does not exist at all (it cannnot).
Do you know what properties are? And what classes are for?

There is no private class and any sign of any property in your example. Private class does not exist at all (it cannnot).
Do you know what properties are? And what classes are for?

that was a private method not a private class.

In general you can't declare methods inside methods (multiply is inside main).

And you can have private classes, no matter what Mitja says :)

You cannot declare other methods inside a method in a C-like language.
Use Pascal or Modula-2 if you like to do that.
A possible solution to your post might be:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = multiply();
        }

        private static int multiply()
        {
            Console.WriteLine("hello");
            return 111;
        }
    }
}

You cannot declare other methods inside a method in a C-like language.

You can in C# :) Anonymous methods.

OK Momerath, you got me ;)
Thanks for reminding!

And you can have private classes, no matter what Mitja says :)

Yes, only nested (I know that, but I actually dont use them - not yet).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.