• Register
0 votes
571 views

Problem :

I am getting into the C# coding but I am having following issue:

I have below code on the UserControl:

using MyFirstDataLayer.Section1;
public class MyFirstClass
{
    protected void MyFirstMethod
    {
MyFirstClass.MyFirstItem oItem = new MyFirstClass.MyFirstItem();
        oItem = MyFirstClass.GetItem();
        someLiteral.Text = oItem.Property1;
    }
}

Everything works fine, but when I go to the access Property1. The C# intellisense only gives me the "Equals, GetHashCode, GetType, and ToString" as options. But when I mouse over the oItem.Property1, the Visual Studio gives me below explanation:

MemberMyFirstDataLayer.Section1.MyFirstClass.MyFirstItem.Property1.getcannot be accessed with an instance reference, qualify it with a type name instead

I am not sure of what this actually means, I did some research but was unable to figure it out.

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Understand what the ‘static’ implies in terms of both the run-time and compile time behavior and syntax.

· The static entity will be automatically constructed some time before
its first use.

· The static entity has one storage location allocated to it, and that is
shared by all other who access that entity.

· The static entity can only be accessed by its type name and not
by an instance of that type.

· The static method does not have the implicit ‘this’ argument, as does the instance method.

· Please think about thread safety when using static entities.

9 7 4
38,600 points

Related questions

0 votes
1 answer 10 views
10 views
Problem: Today I was working on c sharp and I'm trying out static classes, but it doesn't seem to work for me and I would love to know the solution. I have been browsing around the web for a while now but I can't seem to find the answer. Here is my code: class Count { ... ; Count add = new Count(); int total = add.sum(num1, num2); Console.WriteLine("The sum is {0}.", total); Console.ReadLine(); }
asked Apr 25 muktaa 34.4k points
0 votes
1 answer 1 view
1 view
Problem: Today I was working on c sharp and I'm trying out static classes, but it doesn't seem to work for me and I would love to know the solution. I have been browsing around the web for a while now but I can't seem to find the answer. Here is my code: class Count { ... Count add = new Count(); int total = add.sum(num1, num2); Console.WriteLine("The sum is {0}.", total); Console.ReadLine(); } }
asked Apr 25 sumaiya simi 43.9k points
0 votes
1 answer 6 views
6 views
Problem: Everything works fine, except when I go to access Property1. The intellisense only gives me "Equals, GetHashCode, GetType, and ToString" as options. When I mouse over the oItem.Property1, Visual Studio gives me this explanation: MemberMyDataLayer.Section1.MyClass.MyItem.Property1. ... a type name instead I am unsure of what this means, I did some googling but wasn't able to figure it out.
asked Mar 30 ummesalma 29.2k points
0 votes
1 answer 37 views
0 votes
1 answer 55 views
0 votes
1 answer 16 views
16 views
Problem: I am very new to C# and Asp.net. I have tried to write the below code: protected void Page_Load(object sender, EventArgs e) { num = Convert.ToInt32(Request.QueryString["RegNo"].ToString()); if (!IsPostBack) { BindTextBoxvalues(); }     } But my above code is ... for the past few days, I have also taken the help from the colleagues in my team but still I am facing the same old error.
asked Sep 3, 2020 Raphael Pacheco 4.9k points
1 vote
1 answer 3 views
3 views
Problem : Any solution for this please: Static member cannot be accessed with an instance reference.
asked 4 days ago PkGuy 23.5k points
0 votes
1 answer 13 views
13 views
Problem: I need someone's help to solve it .. Cannot be accessed with an instance reference
asked Mar 19 Ifra 34.7k points
0 votes
1 answer 78 views
78 views
Problem : I am facing below error if I try to export datagrid to the excel. &ldquo;Control 'gridview1' of type 'gridview' must be placed inside a form tag with runat=server.&rdquo; Please find below my code : <form runat="server" id="form1"> <div runat="server" id=" ... TextBox> </form> My GridView is within the from tag with the runat="server", but still I am facing above error. How to fix this?
asked Feb 17, 2020 mphil 2.3k points
0 votes
1 answer 30 views
30 views
Problem: are you missing a using directive or an assembly reference.
asked Feb 18 charles mathews 5.5k points