• Register
0 votes

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

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 17 views
0 votes
1 answer 35 views
0 votes
1 answer 10 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 Raphael Pacheco 4.9k points
0 votes
1 answer 44 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 mphil 2.3k points
0 votes
1 answer 73 views
Problem : I want to deploy my ASP.NET application. I have tried deploying my site to IIS, but when I visit it with the browser, it gives me following error : Server Error 500 - Internal server error. There is a problem with the resource you are looking for ... error: The page cannot be displayed because an internal server error has occurred. I want to see the actual issue behind my server error?
asked Dec 7, 2019 alecxe 7.5k points