• 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

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 26 views
0 votes
1 answer 45 views
0 votes
1 answer 14 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
0 votes
1 answer 65 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 12 views
Problem: are you missing a using directive or an assembly reference.
asked Feb 18 charles mathews 3.9k points
0 votes
1 answer 12 views
How do you convert a numerical number to an Excel column name in C# without using automation getting the value directly from Excel.?
asked Aug 28, 2020 Aliza313 720 points
0 votes
1 answer 130 views
Problem : I have recently installed a website on my local machine using IIS 7 successfully. But when I tried to deploy it on the live server, I got a following error: "The page cannot be displayed because an internal server error has occurred" Nothing else. Using a same IIS 7 on live and also set to have the Detailed errors in Error Pages module, but still getting a same. What can be the reason?
asked Jan 28, 2020 jwilliam 3.9k points
0 votes
1 answer 145 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
0 votes
1 answer 4 views
Problem : cannot drop database because it is currently in use
asked Feb 24 Shovo210 3.9k points
1 vote
1 answer 38 views
Problem : I am very new to ASP.NET. I have recently tried to install ASP.NET and Web Tools. After installing the new ASP.NET and Web Tools 2015 (RC1 update 1) I am often facing the below error within my ASP.NET MVC 4 projects if I try to open the *. ... of time in fixing above error but still face the same visual studio error. So I am looking for Visual Studio experts help in fixing above error.
asked May 12, 2020 stewart 4k points