Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

C# Help


  • Please log in to reply

#1
Dsypher

Dsypher

    Member

  • Member
  • PipPip
  • 97 posts
Hi,

I get the error:

HelloWorld.cs(10,20): error CS0122: 'MyName.MyName(int)' is inaccessible due to its protection level

for the following simple C# program. I'm a newbie in C# so can sum1 help me out here plz !! :tazz:

using System;

public class HelloWorld
{
    public static int Main( string[] args )
    {
        Console.WriteLine( "Hello C# World" );
        
        int n = 20;
        MyName M = new MyName( n );
        int r = M.GetNumber();
        
        Console.WriteLine( "Number = {0}", r );
        
        return 0;
    }
    
}

public class MyName
{
    int num;
    
    MyName( int n )
    {
        num = n;
    }
    
    public int GetNumber( )
    {
        return num;
    }
    
}

Thanx.
  • 0

Advertisements


#2
timinator

timinator

    Member

  • Member
  • PipPip
  • 18 posts
Change this:
   MyName( int n )

to this:
   public MyName( int n )

  • 0

#3
Dsypher

Dsypher

    Member

  • Topic Starter
  • Member
  • PipPip
  • 97 posts
Hey thanx timinator !

But I thought that if "public" isnt used it takes "public" by default??

Thanx again
  • 0

#4
timinator

timinator

    Member

  • Member
  • PipPip
  • 18 posts
No, the default access for class members is "private".
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP