C# - Why Only Static / Shared Version Of ForEach For Arrays

Aug 18, 2011

Why there is only a static/shared version of ForEach for arrays?
IE: ForEach<T>(T array[], System.Action(Of T) action[])
I assume this has something to do with the type inference requirements of implementing an instance method, but when you declare your array you provide type right?

View 2 Replies


ADVERTISEMENT

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# - Reset A Static/shared Class?

May 4, 2009

I've got a shared class (static in C#) which mostly carries some settings data that any class in the application can read and sometimes write. Also there are some static properties which holds some internal states.

Now I want to revert this class to initial stage of it. With all default variables etc. Assume that the user want to reset the current state and start over without restarting the application.

In a singleton model I'd simply renew it with something like this :

Public Sub Reset()
_Instance = New MyClass()
End Sub

However this is not possible in a Shared class. Or should I switch back to Singleton?

View 3 Replies

C# - Static (Shared In VB) Or Normal Methods

Oct 27, 2009

I Want to know which one is preferred while coding to use Static Methods or normal instances, I prefer to use static if they where few but if there was many of them I start to get some doubts

[code]...

if the EmployeeManager Has Many methods (selects deletes updates) is it ok to make them all static.and if it was Normal instance. wouldn't be a drawback if the object is initiated every time specially if GetAllEmployees() is heavily used.What is the better approach to use?

View 3 Replies

Difference Between Static And Shared Variables In .NET?

Jun 22, 2009

exact diff b/t Static v/s Shared variables in VB.NET?

View 3 Replies

Generate A URL Within A Shared (static) Method In MVC.NET?

Sep 27, 2009

I'm creating a Shared (static) method in ASP.NET MVC so it can be used by any controller in my project. This static method needs to generate a URL. I think I need to use System.Web.Mvc.UrlHelper, but I can't figure out how to call it from within a static method.The constructor seems to want a RequestContext.

View 1 Replies

LoadControl In Static / Shared Function

Dec 30, 2009

how I can dynamically load a control inside of a shared/static function?The function itself is inside of a mustinherit/abstract class.(It's an ASP.NET project in VB) I want to do something like this:[code]I'm getting "Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.",but I don't understand this error.I understand what it means, I just don't understand why calling LoadControl isn't seen by the compiler as being an explicit instance of the class. What's not explicit about using LoadControl to create a new control from a file? I tried creating a new user control and initializing it, then setting it to a different control with LoadControl to no avail.I also don't want to do a DirectCast because I'm trying to put this in a shared, mustinheret (abstract) class, which therefore doesn't have an .aspx file to write in a <%@ Reference Control="~/SomeControlPath.ascx" %>, so the class name is unavailable.What I'm trying to do is write a static function that takes some value and returns a control based only on that control's source file location.The end result is a user-modifiable list of controls.They get a column of controls that they freely add, remove, or reorder based on a static list of available child controls that I specify.

View 4 Replies

Possible To Have A Shared/Static Dependency Property?

May 25, 2010

[using VB.NET, but I can easily read C# code in responses]I have a class called QuestionClipboard with ALL shared methods/properties. I previously had a QuesitonClipboard.doesClipboardHaveContent function that returned true/false if there was a Object on my 'clipboard'.I'd prefer to implement a Dependency Property so I can allow this true/false value to participate in data binding.The "GetValue(dp as DependencyProperty)" method requires an object instance, which would mean that my Property CAN'T be shared!Here is what the code would look like in my perfect world... Of course, the word "Shared" before the property declaration renders this code useless.

Private Shared clipboardHasContentPropertyKey As DependencyPropertyKey = DependencyProperty.RegisterReadOnly("clipboardHasContent", GetType(Boolean), GetType(QuestionClipboard), _

[code]....

View 1 Replies

Shared (Static) Classes With Events In C#

Mar 27, 2010

[code]Now how do i do this in c#. I know there is not handles clause in c# so i need some function that is called and assign the event handlers there. However since its a shared class there is no constructor i must put it somewhere outside of a function.

View 2 Replies

Visibility Of Static / Shared Members

Dec 30, 2009

I have faced with a situation in VB.NET and C# (.NET2) with the visibility of the static/shared members. It seems to me a little strange in VB.NET:

public class A {
private static A instance;
public static A Instance {
get { return instance; }
} public string Name { get { } }}
[Code] .....
Shared member behaves like a class public one I can repeat it to infinite..

View 3 Replies

Asp.net - Calling Other Functions From A Shared (or Static) Function

Aug 20, 2010

I get this error: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod()> _

[Code]....

I know it has something to do with the fact that the first function is shared and the second function should probably be Public as well but I don't fully understand the reason behind it. Probably not relevant but I'm calling the web method from some javascript.

View 1 Replies

Asp.net - How To Get Classes To Expose The Same Shared/Static Method

Mar 4, 2010

I have a base class with several derived classes. I want all of my derived classes to have the same Public Shared (static) method with their own implementation. How do I do this? Is it even possible?

View 3 Replies

C# - ASP.NET's App_Code Folder And Shared/Static Classes?

May 15, 2011

If I have a 'Shared' object defined in the App_Code folder; is that object shared amongst all users/visitors of my website? Or is it shared on a per-user basis?I don't know if that makes sense or not; but I've got a puzzle/solver I'd written earlier that I'm trying to incorporate into a simple ASP.Net site. It's probably poorly written, but I'd used a Shared boolean to determine if a solution had been found. The code works, now as an ASP.NET site, but if two visitors to my site were both validating their puzzle at the same time, would they both be accessing the same boolean?

View 3 Replies

C# - Best Practice For Complex Shared / Static Members

Sep 7, 2011

I took over an ASP.NET application and have found this throughout several classes in the application. The programmers before defined several shared/static variables that act as "complex enums" throughout the application. As a fairly new programmer, it doesn't look like best practice.

Here is an example:
Public Shared SecureCommentsWrite As New Task("Secure Comments Write")
Public Shared SecureCommentsRead As New Task("Secure Comments Read")
Public Shared EditEmergencyContact As New Task("Edit Emergency Contact")
Public Shared DisplayPersonalReferences As New Task("Display Personal References")
Public Shared EditPersonalReferences As New Task("Edit Personal References")

The constructor takes the description, then loads the ID key from the database using a stored procedure (the database is SQL Server.) This seems like a good idea since we deploy this application to multiple databases and want to ensure that we load the ID key that's in that database in case it changes. However, since there are literally hundreds of these in the application, the first load takes a while.

View 4 Replies

.net - Prohibit An Instance From Calling Shared/Static Method?

Aug 27, 2010

Is it possible to prohibit an instance of a class from calling a shared/static method?

For example:

I want to allow this:

ClassName.MethodOne()

But I want to disallow this:

Dim A As New ClassName
A.MethodOne()

The reason this is desirable is that in this case it is semantically confusing if an instance can call the method.

View 2 Replies

.net - VB Cross-thread Shared (static) Member Access?

Aug 4, 2010

I'm a newbie to threading, trying to learn it as I go. don't make any assumptions and try to explain threading concepts and rules that might seem obvious. I have a Module (Static class) as follows:

Module Main
Private ReadOnly _dbConn As SqlClient.SqlConnection
Public ReadOnly Property DBConn() As SqlClient.SqlConnection
Get
Debug.Print("Accessing DBConn")

[Code]...

All throughout the application, when i access DBConn on the same thread, it works as expected. howeve, later on I created a background worker that tries to access DBConn and nothing happens, the thread just hanges (the Background worker). I dont get the printout and the application doesnt continue. the background worker thread doesnt continue past that point, and so the thread never exits. I dont get any exceptions, and i Cant debug in Visual Studio (visual studio hangs).I guess its a 2 part question: why cant i access DBConn from the other thread, and why does it hang without giving me a threadAccess exception? also, why does visual studio hang (I'm assuming it hanges because the thread is hanging)?

Please Note: I am not asking about practice. I know I shouldnt be sharing the same connection, rather returning a new connection. in this particular application it is safe since (although i execute it on a background thread) as per the flow of the application, the connection can only be accessed one at a time. I just want to know why it hangs accross the thread.

View 1 Replies

C# - Access A Shared/static Member Through An Instance Variable?

Mar 3, 2011

Here's an example of what I'm talking about...

Public Class Sample1

Public Shared Function MyValue() As Integer
Return 0
End Function
Public Sub Code()

[Code]...

Me.MyValue gives a warning in VB.NET and (the equivalent code gives) an error in C#. Is there a particular reason for this? I find it more intuitive/natural to access the shared function using 'Me.MyValue' - but I avoid it to keep my warnings at 0. Did someone else just decide 'Nah, it makes more sense to do it the other way' or is there some technical reason I don't understand?

EDIT: I was thinking of it wrong, more like a 'sub class' in OOP. Even if something is declared in the base class, you access it through the instance you have. But that relationship is not the same with shared or static.

View 6 Replies

C# - Display Static (shared) Object's Properties In A PropertyGrid?

Apr 12, 2010

I would like to display static (shared) objects at runtime in a PropertyGrid but if I try to set the selected object property of the grid like this:

[Code]....

Is there a way to display a static (shared) object or the object's properties in the PropertyGrid?

View 1 Replies

C# - Storing Static Files To Be Shared Among Azure Roles

Sep 13, 2011

I'm trying to host some static files for access by an ASP.Net web role and a separate data worker role that are both running on the same deployment (they use a global static interface).

However, I'm unsure how exactly to 'host' them, I've tried using virtual folders via HttpRuntime.AppDomainAppPath, but it only occasionally works in debug mode. The files also don't seem to get packaged into the deployment packages made by VS vis CSPack (though this might be a separate issue, is it possible to fix this too?)

The static files in question are actually WordNet, which I'm using through WordNet.Net, If that makes any difference. I also need the solution to work in both the cloud deployment and the emulator (if possible).

View 2 Replies

Singleton Class Or Shared (static) Member Functions?

Aug 9, 2011

I would like to understand the Pro & Cons in using the commonly used methods via Singleton class against Shared (Static) members of a class in VB.Net. It could be in terms Time, Space complexity or best practices. I have a BankAccount class with methods doing some business logic.

GetBalance()
GetLast5Credits()
GetMiniStatement()

[code].....

View 4 Replies

Local Variables In Shared Method Work Like Static Variable In C?

Aug 23, 2011

Will the list in this shared method keep its state throughout the life of the method? Or will a new list be created every time this method is called?

[Code]...

View 3 Replies

Self-referencing Current Type's Name (static Version Of Me/MyClass)?

Mar 16, 2010

Traditionally, class/type name is literally spelled inside its definition.

Public Class MyCustomClass
Public child As MyCustomClass
Public Shared Function Clone(ByVal original As MyCustomClass) As MyCustomClass
End Class

This is not a problem most of the time; C-languages even use class name as constructor methods' name. But consider a generic declaration:

Public Class MyListOfIntegers
Inherits MyCustomList(Of Integer)
End Class

[code]....

This scenario has 2 issues. The first one is that constructors are not inherited, and you have to provide pass-through wrappers in every derived class, — this is quiet dumb, but tolerable. The second issue is more severe: derived class inherits CloneMe() method which returns MyCustomList(Of Integer) , not MyListOfIntegers ! Every returned value must be manually DirectCast 'ed for further use with methods that expect MyListOfIntegers . This issue, together with the first one, renders inheritance of generic class almost useless.

So I need a "MyClass" alternative for static type-binding inside type definition. In case of generic type that is referencing other compound types, task could be accomplished by adding second parameter to type section:

Public Class MyCustomList(Of T, TList)
...
Public Function CloneMe() As TList

[code]....

But since we must reference our own type, it would create an infinite recursive loop of additional typeparamlist arguments. How can this be resolved, aside of creating separate classes without generics?

View 11 Replies

IDE :: Assembly Version, File Version And Publish Version In ClickOnce In VS 2008

Mar 31, 2009

How they relate and differ from each? What are the best practices for version control? Is there a primer about publish online? Or a good book?

And is it possible to make ClickOnce and a msi in one solution of VS 2008? If so, is there any conflict or pitfall?

BTW I am using VB if that makes any difference.

View 1 Replies

.net - Why Can't Call Private Shared Methods From A Public Shared Method

Aug 25, 2011

I have a class like this:

[Code]...

It works, when I make getBar methods public, but I don't want to expose these unneccessarily. Why I can't call private shared methods from a public one in the same class is over my head. I'm using .net framework 4.0 in a web application.

View 1 Replies

Asp.net - Public Shared Variable Shared Between Users?

Mar 30, 2012

I've taken over the maintenance of the website (ASP.NET VB) and on one particular page I noticed the below code

Inherits System.Web.UI.Page
Public Shared UserNumber As String
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

[Code]....

My question is whether the variable UserNumber can be accessed or changed by any other user than the current one?

View 2 Replies

Shared Method Not Calling Shared Constructor

Aug 12, 2009

Given in the following language specification, for me at least, calling Db.Foobar() [In the following code] does not indeed call off to the Shared Constructors of the base classes. I am curious as to a) is this my own fault for doing something wrong or b) is this an error in the language specification[code]...

View 2 Replies

Code That Works In Excel Version 2003 Does Not Work In Version 2007

Oct 21, 2008

This code no longer works in ver 2007:' Obtain max resources available for Excel

[Code]...

View 3 Replies

Make Programs Use A Lower Version Of Net.framework Other Than The Newest Version 4 That Comes With VS2010?

Jun 10, 2010

Is there any way to make my programs use a lower version of net.framework other than the newest version 4 that comes with VS2010?I use my programs within a closed network and there isn't an easy way for me to install any software since I'm not the administrator.

View 3 Replies

Disable Button Depending On OS Version By Reading OS Version Via Registry?

Jul 29, 2009

I'm trying to add functionality to my application that will disable buttons and checkboxes depending on what version the OS is when the app is launched. I made a test app to test this but unfortunately I can not get it to work. Here is my code:

'OS Check
Dim osValue As Object
osValue =
My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrent Version", "CurrentVersion", "5.2")

[Code]...

*Note - 5.2 is Windows 2003, 6.0 is Vista, 5.1 is Windows XP

View 1 Replies

VS 2008 Check Difference Between A Full Version And Unregistered Version?

Sep 1, 2010

I have created a license system for my application with MySql about half a year ago. What it would do is take the serial number and send it to my server if the key was correct it would return a 0 if its wrong the return value would be a 1.The problem was that when the serial number was entered correctly my program would create a "fake file" for example vb.dll in the system.And on run time my program would check for that vb.dll if the file exist it would skip my trial program and run the app as a full version. Half year later i think creating a "fake file" and checking for it on start up is extremely wrong and that's not very good security.How can i check the difference between a full version and unregistered version?

View 23 Replies







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