Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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