Private Fields Have To Be Declared Static?

Aug 18, 2010

I am a vb.net programmer switching to C#.I have the following code for a console application (targeting NET20)

using System;
using System.IO;
using System.Data;[code]....

This is giving a compile error in the if clause of InitVars for the _dbName variable:

Error 1 An object reference is required for the non-static field, method, or property 'eScoreSwapper.Program._dbName' C:UsersSethSDocumentseScoreVersionsTrunkdotNeteScoreSwappereScoreSwapperProgram.cs 26 38 eScoreSwapper

C# does not allow you to reference private class fields unless they are declared static?

View 7 Replies


ADVERTISEMENT

C# - When Should Use Public / Private / Static Methods

Apr 27, 2009

I'm new to C#.Till this moment I used to make every global variable - public static.All my methods are public static so I can access them from other classes. I read on SO that the less public static methods I have,the better.So I rewrote my applications by putting all the code in one class - the form class.Now all my methods are private and there's no static method.

My question: What should I do,keeping everything in the form class is dump in my opinion. When should I use public,when private and when static private/public? I get the public methods as a 'cons' ,because they can be decompiled,but I doubt that.My public methods can be decompiled too.What is so 'private' in a private method? EDIT: I'm not asking how to prevent my program to be decompiled,I'm asking whether I should use static,private and public.And also : Is there are problem in putting all the code in the form class so I dont have to use public methods?

View 6 Replies

What Use Cases Exist For Non-static Private Or Protected Events

Sep 25, 2009

What purpose do protected or private (non-static) events in .NET really serve?It seems like any private or protected event is more easily handled via a virtual method. I can (somewhat) see the need for this in static events, but not for normal events. Have you had a use case before that clearly demonstrates a need or advantage for a non-static protected or private event?

View 5 Replies

Asp.net - Updating A Hybrid DetailsView (with Static And Dynamic Fields)?

Dec 12, 2011

I've got a DetailsView which has some static fields defined in my markup and adds some extra fields dynamically in the VB codebehind. It should be noted that the DetailsView lives in an UpdatePanel.Assume that I would like to get inventory information for a number of warehouses, but I only want to see those which have stock on hand. In addition I have some static information such as product, sku, etc.

The problem I was having was that every time I clicked the "Details" button it would just keep appending the dynamic fields to the end and never re-rendering the table. I figure I either need a conditional or to tell it to re-render somehow. I suspect this problem arises from my use of the UpdatePanel but it's important for the user experience of my customer to keep this.

'Warehouse Stock by Location
Dim stockDT As New DataTable
For Each row As DataRow In stockDT.Rows 'Add column for each Warehouse that has stock

[code]....

View 1 Replies

New Static Fields And Hiding The Public Inherited Members?

Feb 3, 2010

Curious situation:
public class MyTextBox : TextBox
{

[code].....

View 1 Replies

VS 2010 Using Reflection Difference Between Static And Instance Fields And Properties

Jun 6, 2012

I'm trying to obtain the values using the prospective GetValue(s) methods but I don't understand the syntax of the documentation. I'm sending the correct bindings (I believe) to filter the fields, and properties that i'm interested in usually

[Code]...

View 3 Replies

Official Notation For Private Fields?

May 13, 2009

Is there any official notation for private fields? Like mVar, m_var or another notation?

View 10 Replies

Private Fields Or Local Variables?

Apr 18, 2012

I am wondering if you have a class and in the class you have a function which executes a sqlcommand. Which would u use ? the local variable declaration or the private member command variable.Assuming that the class has a private field called m_Cmd as OracleCommand..i am using oracle db so i use oraclecommand , if sql server then it should be sqlCommand.[code]

View 3 Replies

Transactions - Expose Private Fields Using A Partial Class?

Nov 12, 2010

I am trying to implement transactions across multiple TableAdapters in VB.NET (using Visual Studio 2010) by extending the partial class as described in the following examples:

http://blah.winsmarts.com/2006/06/18/the-definitive-tableadapters--transactions-blog-post.aspx
madprops.org/blog/typed-datasets-and-sqltransaction/
stackoverflow.com/questions/2342289/net-tableadapter-to-dataadapter

However, when I attempt to expose any of the private fields created by the designer they are underlined in the editor with the following error:

'_adapter' is not declared. It may be inaccessible due to its protection
level.

Searching this site as well as google has not revealed anything useful, but perhpas I'm searching the wrong keywords.

Here is the code in MyDataset.vb

Partial Public Class MyTableAdapter
Public Property MyTransaction() As SqlTransaction
Get

[code]....

View 1 Replies

Private Fields Flagged As WithEvents Are Taken By Code First To Build An Automatic Foreign?

Jan 22, 2012

a simple question. Given the following code:

Public Class MyClass
Private WithEvents pPerClass As PersistableClass
Public Overridable Property PerClass() As PersistableClass
Get
Return pPerClass

[Code]...

the first being a duplication of the second key, strangely obtained from a private field.

If you remove the WithEvents keyword, the pPerClass_PersistableClassID key is not created.

I am new to EF but it seems to me a strange behaviour.

View 1 Replies

VS 2008 Sharing Variables - Private Sub Could Use The Variable Created On Private Sub

Jul 23, 2010

if for example i have two private sub I declared a local variable on private sub a... is there a way that private sub b could use the variable created on private sub a? Im asking because im in a problem in my app were using global variable is not an option to make the long story short

View 5 Replies

What’s The Difference Between Private Sub And Private Function

Dec 14, 2011

I am completely lost on procedures. Whats the difference bewteen Private sub and private function?

View 1 Replies

Declared Variable Appearing Not Declared?

Feb 24, 2011

The following is a screenshot of the problem: What can I do?

View 3 Replies

Refactoring A Module Into A Class: Changing Shared Fields To Instance Fields

Nov 14, 2011

I'm currently refactoring an old Visual Basic DLL (VB.Net), which stores all of its data in one module called Globaldefinitions as public fields. There are about 200 fields, referenced thousands of times all around the code:

Public Module Globaldefinitons
Public a As Short
...
Public zz10 As Double

[Code]...

I need to change the module into a class with non-shared fields. This means, each and every of these thousands of references needs to reference the instance of that class:

globalDefinitionsInstance.a = 5

How do I go about this efficiently?

Regular expressions operating on the source fall flat. Refactoring tools like Re-Sharper or CodeRush don't seem to offer this functionality. Visual Studio 2010 cannot do it automatically either.

View 2 Replies

Can The Initialization Order Of Class Fields In .NET Be Influenced By References To Other Fields

Jun 19, 2011

Class Foo
ReadOnly name As String
Public Sub New(name As String, dependentUpon As Foo)
Me.name = name

[code]....

The output of New Bar() is:

Dependent created. Dependent upon nothing.
Independent created. Dependent upon nothing.

It seems fields are initialized in the same order as they appear in the source code, which (a) leads to an unexpected result, and (b) seems a little puzzling, given that one is normally not permitted to read from uninitialized variables in .NET, yet that seems to be working fine above.I would've expected VB.NET to be smart enough to initialize referenced fields first, and only then those that reference it; i.e. I'd have liked to see this output instead:

Independent created. Dependent upon nothing.
Dependent created. Dependent upon Independent.

how to get VB.NET to behave like that instead, without simply having to swap the declaration order of dependent and independent inside class Bar?

View 1 Replies

Create Word Form Fields With Memo Fields From Access?

May 27, 2012

I'm trying to create a table in Word using data from a table in Access. There are four fields in the access table that I need. 3 fields are text which I can populate the Word without any issues. However the fourth field is a memo with >255 characters.I'm struggling to come up with the proper code to allow me to populate the Word field with the memo data that has more than 255 characters. The code I have so far is listed below. But when it hits the memo field, it crashes on the line I marked with **. I know it's not text, but I've tried many different field types, but nothing has worked so far.[code]...

View 1 Replies

Validating Login Fields - Check The Username And Password Fields

Jan 14, 2012

My intent is to have the code - on a button.click event - check the Username and Password fields and return an error depending on which is wrong. Or if both are wrong, return a different error message. I've set the username as parts and the password as parts (still learning how to use external authentication). [Code]

View 2 Replies

Gridview Combine Autogenerated Fields And Template Fields

Aug 17, 2010

I have several sqldatasources for my gridview. All of the columns are autogenerated. However they all have some consistent fields and I'd like to make those fields template fields so I can modify the edit template for them such as adding a drop down menu. Is this possible?

View 1 Replies

C# - MS Word Office Automation - Filling Text Form Fields And Check Box Form Fields And Mail Merge

Sep 3, 2009

experience on how to create an engine using C# (VB.NET is okay too) that is generic enough to handle most cases of MS Word text fields I need to fill with data I'm getting from a database? In short, I'm about to embark on this little Office automation excursion and I'm hoping a little bit of feedback here.

View 2 Replies

Database - Compare Two Fields In An SQL SELECT Statement To Then Select Other Fields Based On This Result?

Apr 8, 2012

I have a table which contains a list of products for a company. They input data about how much stock they have and also the level at which they want to be reminded that they need to order new stock.

[Code]...

I want to list all the true results in a form which the user is then able to navigate through. What would be the best way to go about doing this?

View 2 Replies

Combining Multiple Table Data With Different Fields Into A Single Table With All The Fields?

Feb 13, 2012

how to execute this SQL Statement

Scenario:
Given Tables T_Data, T_AllDesc, T_System1, T_System2
Given Fields:
T_Data= f_id, f_Desc, f_CreationDate, f_CreationTime, f_System1, f_System2

[Code].....

View 7 Replies

Calling Private Subs In Another Private Subs?

Jun 15, 2009

I'm trying to call a private sub in another private sub. For example ;

[Code]....

View 13 Replies

Difference Between Public Sub And Private Sub And Private Function And Public Function And Sub And Shared Function?

May 31, 2011

explain me the difference between them? I'm new to visual basic, and I need to know the very basic things in Visual Basic allowing me to become a professional User

View 8 Replies

Static Constructor In .Net?

Feb 9, 2010

I am rewriting a C# class in VB. The C# class has a static constructor in it:

static Class()
{
...
}

which, through the Call Stack, I found is called by the main window's InitializeComponent() method.Everywhere I've looked has told me that the corresponding static constructor in VB is just:Shared Sub New()

but this method is never invoked. Am I creating my VB static constructor right? Is it likely something else that has nothing to do with my static constructor?

View 1 Replies

Static Variable In Asp.net?

Dec 15, 2011

I am writing a code for a webapplication in vb.net. I am using a shared variable in the vb code.

Consider the static variable value is 3 for a user who hits the web application. Again when another user hits the same web application, whether the static variable will be 3 again or whether he will have a separate value for static variable for his session?

View 1 Replies

.net - LINQ And Static ObservableCollection?

Nov 7, 2011

This will probably be a basic questions for the LINQ & architecture experts however I am failing to understand a problem i've encounted when trying to update a 'Static ObservableCollection.

Me.Grid1.ItemsSource = ContactList Me.Grid2.ItemsSource = From s In ContactList Where s.ContactTypes.Any(Function(t) t.ContactTypeName = "Christmas List")

If I add a new Contact with the ContactType "Christmas List" to the ContactList ObservableCollection, Grid1 reflects the additional Contact however Grid2 does not reflect the change unless I rebind.

Anyway to Reflect the change in Grid2 to show the new Contact with the queried ContactType

View 2 Replies

.net - Static DateTime For Testing?

Dec 11, 2009

We have a DateTime Service that pulls the Database date down when we need to use a Date. Now, If I want to run a test using "Todays" Date using FitNesse, What would be the easiest way of creating a way to have (OurService).CurrentDate be static? We have a control that ads Days,Years, or Months to the current date.. and I would like to be able to test this.

View 1 Replies

Adding A Static Crypt Key?

Jul 15, 2011

I am currently using Visual Basics 2010 (Ultimate), and I am trying to modify a free-project listed here:I want the above project to use these hard-coded values below:Key= "087CF262E0E856B8F911B369EE027CF9330F6288343651B1198379A9813BC8C4"
IV = "11D2A07242B79C752E6B53CDD14792C9"So basically i want to encrypt AND decrypt with the above keys.

View 8 Replies

C# - Shared / Static Variable Should Be Nothing?

Jan 6, 2011

I have the following code:
Public Class TestClass
Public Sub Main()
If theGlobal IsNot Nothing Then Throw New Exception("What gives!")
End Sub
Private Shared theGlobal As Object = Nothing
[Code] .....
Why is theGlobal object NOT Nothing?

View 2 Replies

C# Vb: When They Say Static Classes Should Not Have State?

Apr 23, 2011

when they say static classes should not have state/side effects does that mean:

static void F(Human h)
{
h.Name = "asd";

[code].....

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved