class inaccessible

T

tshad

I am getting a message for my objects that say:

testNulls.cs(13,33): error CS0122: 'FtsData.IntType.IntType()' is
inaccessible due to its protection level

I have a class calling objects out of another class, but same namespace.

This is the class that gets the error:
**************************************************************
namespace FtsData
{
[Serializable]
public class TestNulls
{
private IntType testNullsID = new IntType(); <---------
Error line
private StringType firstName = new StringType();
private DecimalType salary = new DecimalType();

public TestNulls()
{
salary.Data = 12345;
}
....
************************************************************

The class that defines the IntType objects:
*************************************************
using System;

namespace FtsData
{
[Serializable]
public class IntType
{
private int first = 0; //original data
private int data = 0; //current data
private bool nullFirst = false; //original Data null
private bool nullData = false; //current data null

private IntType()
{
}

private IntType(int initial)
{
first = initial;
data = initial;
}

public bool IsNull()
{
return nullData;
}

public bool IsFirstNull()
{
return nullFirst;
}

public void SetNull()
{
nullData = true;
data = 0;
}

public void SetFirstNull()
{
nullFirst = true;
first = 0;
}

// Properties

public int First
{
get { return first; }
set { first = value; }
}

public int Data
{
get { return data; }
set { data = value; nullData = false; }
}
} // end Class

****************************************************

There are a bunch of classes - one for each datatype.

But I am getting an error trying to instantiate the object, but not sure
why?

Thanks,

Tom
 
B

Bruce Wood

....because you said:

private IntType()
{
}

private IntType(int initial)
{
first = initial;
data = initial;
}

....which says, "There are only two ways to instantiate an object of
this class: one is a parameterless constructor, the other is by
supplying a single int value. However, this class itself is the only
thing that can create an instance of itself."

You marked the constructors "private", which means that they're
accessible only from within the IntType class itself. If you want other
classes to be able to create IntType objects directly, you'll have to
make at least one constructor "public".
 
T

Tom Porterfield

tshad said:
I am getting a message for my objects that say:

testNulls.cs(13,33): error CS0122: 'FtsData.IntType.IntType()' is
inaccessible due to its protection level

I have a class calling objects out of another class, but same namespace.

This is the class that gets the error:
**************************************************************
namespace FtsData
{
[Serializable]
public class TestNulls
{
private IntType testNullsID = new IntType(); <---------
Error line
...
The class that defines the IntType objects:
*************************************************
using System;

namespace FtsData
{
[Serializable]
public class IntType
{
private IntType() // change this to public if you need to invoke this constructor from another class.
{
}

Your parameterless constructor for IntType is private which means you
cannot invoke that constructor outside of the class. If you want to
call that constructor from a different class then you need to change its
protection level to public.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top