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");

                
            }
           }

   }

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?

Edited 5 Years Ago by Mitja Bonca: n/a

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.

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).

This article has been dead for over six months. Start a new discussion instead.