What Is The Point Of Static

Feb 23, 2010

explain to me the point of static?

Say I have a class called GenericFunctions and a function in there called FormatAddress.

If I want to access that function I have to do this:

Code:

GenericFunctions GF = new GenericFunctions();
string FormattedAddress = GF.FormatAddress(int AddressID);
If I make FormatAddress static I can access it without creating an instance of the class by just calling

Code:

string FormattedAddress = GenericFunctions.FormatAddress(int AddressID);
So, making the function Static means I don't have to create an instance of the class. So, what's the point? Why not make everything Static?

View 30 Replies


Similar Messages:

Visual Studio :: Unable To Attach. The Binding Handle Is Invalid/ Not Point To The Break Point?

Dec 13, 2010

Not point to the break point.it gives above error massege when start debbuging. How i fix this.

View 1 Replies

C# - Is It Safe To Access .net Session Variables Through Static Properties Of A Static Object

May 10, 2010

Is it safe to access asp.net session variables through static properties of a static object?Here is what I mean:

public static class SessionHelper
{
public static int Age
{
get
{
[code]...

Is it possible that userA could access userB's session data this way?

View 2 Replies

C# - How To Lock A Private Static Field Of A Class In One Static Method

Mar 26, 2011

I have a private static field in my Controller class in an MVC web application.

I have a static method in that controller that assigns some value to that static field, I want to apply lock on that static field until some other instance method in the controller uses the value stored in the static field and then releases it.

DETAILS:

I have a controller named BaseController having a static ClientId field as follows and two methods as follows:-

public static string ClientId = "";
static void OnClientConnected(string clientId, ref Dictionary<string, object> list)
{
list.Add("a", "b");
// I want the ClientId to be locked here, so that it can not be accessed by other requests coming to the server and wait for ClientId to be released:-
BaseController.clientId = clientId;
}
public ActionResult Handler()
{
if (something)
{
// use the static ClientId here
}
// Release the ClientId here, so it can now be used by other web requests coming to the server.
return View();
}

View 1 Replies

AJAX :: Calling Non-static Methods From A Static Method?

Jun 30, 2010

I did some research after posting. All I found was simple examples for no-layer architectures, like connecting to a database from your aspx page, so, in a corporate environment, it is unnaceptable.

I need to call a server-side method (using ASP.NET Ajax) in a 3-layer architecture.

For example, my Default.aspx contains a method LoadProducts().

[Code]....

[Code]....

This cannot change. There is no way to convert Business and Data layers to static.

How can I call the LoadProducts() method using ASP.NET Ajax?

View 2 Replies

Public Static Variable Declared In Public Static Class MyGlobals In A 'Code File' Template?

Jan 27, 2011

I have a question about C Sharp ASP.NET:Is there a difference (in code speed, resources) between:public static variable declared in public static class MyGlobals in a 'Code File' template;and the variable declared in a normal 'Class File' template;I use this variable in 2 different Class Files and also in _Default Page codebehind cs file.In fact in my case I need about 20 global variables of type List<string>.

View 9 Replies

Architecture :: Should The Unit Of Work Point To The Service Layer Or The Repository And Then The Repository Point To The Service Layer

Jan 26, 2011

Just wondering, in an ASP.NET MVC3 environnement with entity framework. Should the Unit of Work point to the service layer or the repository (and then the repository point to the service layer) ?

Ive saw two example:

* One where the unit of work and repository both have an instance to the service layer..

Link: Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable

Doesn't use a service layer but its obvious that one could be use in that case.

* Second where the unit of work have an instance to the repository which have an instance to the service layer..

[URL]

What would be better ?

View 11 Replies

Working With Static Variables / Store The User Specific Information In Static Variables?

Mar 5, 2011

whats the exact use of static variables in overall programming in .net and for asp.net...

Recently i went for the interview where interviewer asked me 2 question which i was not sure for the same..

whats the use of session object, i said sessions are the server side object, they are used when you want to store user specific data at server side, then he asked what if i want to use static variables for the same, i was mum, can anyone tell me how asp.net will behave if i store the user specific information in static variables.If i use cookies which are the best option to store the data at client side (not sensitive one), but what if user has disabled cookies on his machine, will my application would crash.

View 3 Replies

What Is The Point Of Throwing An Exception

Apr 15, 2010

What is the point of throwing an exception? It it anyways going to be caught in the Global.asax Application_Error method.

Lets say in the following code we throw an exception.

try {
using (var dc = GetDataContext())
{
// We are doing some data inserts here.
}
catch ( Exception ex)
{
throw ex;
}

My Question: Even if we do not use try catch and throw here, any exception which will be raised here will be caught inside Application_Error method in Global.asax. Then what is the point of try, catch and throw in this case?

View 7 Replies

Different Domains Point To Different Project?

Feb 26, 2011

Question, I have a few asp.net c# projects... but I only use one webhosting to host all the projects. My question is,

Is it possible for me to register like 2 domains and point each domain to 2 projects within that web host?

For example:

Http://mysite1.com will point to the "../project1/default.aspx"
http://mysite2.com will point to the "../project2/default.aspx"

View 7 Replies

Is HTML5 A Break Point

Nov 10, 2010

HTML5 is just an updating to XHTML 4.1 or it brings some thing different and new to the web world ,, what are the major differences between it and its predecessors..

View 1 Replies

What Is The Point Of Unit Testing

Apr 3, 2011

I have been looking at the unit testing topic and honestly I have never yet seen it in a live application.

Im a little foggy on the subject....
A simple example is if I am populating a listbox with data, I would know through debugging if the data is being populated and if it wasnt it would probably be easy to figure out why. Futhermore I couldnt possibly put it in production if it wasnt work so, why would I need to do a unit test? I dont see the point of it.

View 4 Replies

Created A Web App / Entry Point?

Nov 24, 2010

Just created a blank "ASP.NET Web Application". Where's the entry point?

I see "Default.aspx" which seems to be the default template that calls. "Site.Master" which I guess acts as a layout file. "Global.asax" that seems to provide some method stubs for event handling. And then "Web.config" which seems to have some site-specific settings such as a DB connection string, and some authentication stuff.

But no where do I see any "routes" or anything to indicate that "Default.aspx" should be called by default, or "Global.asax" should be used to handle events. Where's this stuff specified? Is it baked into the core of ASP? Can't I filter all the requests through one C# method and then delegate how I please? And return some sort of Http response?

View 4 Replies

How To Add A Decimal Point To A String

Jun 28, 2010

If I have a string/integer that looks like 123, how can I convert that to look like 12.3?Basically what I need is something faster (if possible) than thisMath.Round(Double.Parse(input / 1000), 1).ToString

View 1 Replies

Use Of MaskedEditExtender With Decimal Point?

May 21, 2010

I am using Ajax extender controls with asp.net 3.5 in particular MaskedEditExtender.My settinngs are:

Mask = 99.99
InputDirection = RighttoLeft
MaskType = number.

I can't seem to achieve what I want which is to set the focus just to the left of the decimal point. I try both InputDirection RightToLeft and LeftToRight. They both have problematic behavior. The example given by Microsoft on their web site, is close to want I want but I cannot achieve these results.See

View 1 Replies

URL Rewriting To A Common End Point?

Jun 10, 2010

I want to create an asp.net white-label site [URL], that could be styled for each of our clients according to their specific needs. So for example, client abc would see the site in their corporate colours and be accessed through their specific url http://abc.com. Likewise client xyz would see the site in their own styling and url http://xyz.com.

Typing either url, in effect, takes the user to http://whitelabel.com where the styling is applied, and the client's url structure is retained.

I was thinking of URL rewriting using URLRewriter.Net [URL], or similar, mapping the incoming address to a client id and applying the theme accordingly. So, a url rewrite rule may be something like

<rewrite url="http//abc.com/(.+)" to="~/$1?id=1" />
<rewrite url="http//xyz.com/(.+)" to="~/$1?id=2" />

I could then read the id, map it to the client, and with a bit of jiggery-pokery, apply the correct theme.

View 3 Replies

Highlight Point On Image Map?

Feb 16, 2010

I am working on imagemap, there are points on my image, I want to mark one of point upon clicking of a button, how can I can control the coordinates because my image is resizeable/dynamic, every time image size will be changed.

View 1 Replies

Point Actions To The Same View?

Feb 3, 2010

I have a controller with the following actions...

public ActionResult YellowList()
public ActionResult RedList()
public ActionResult BlueList()

All these actions populate the same viewModel (ListViewModel).

How do I get them all to point to the same view (aspx)?

View 2 Replies

WCF / ASMX :: End Point URL In Web Services?

May 12, 2010

What is End Point URL in Web Services?

View 1 Replies

Want To Develop Point Of Sale Application ?

Oct 5, 2010

i am a c# dot net developer. i am given task to build a Pos application in c# for a grocery shop. i have no idea to develop it, please provide me if there is a tutorial, any class diagram or open source project

View 1 Replies

Visual Studio :: Break Point Will Not Currently Be Hit?

Jul 20, 2010

Break point will not currently be hit.No Symbols have been loaded for this document"

View 1 Replies

MVC :: How To Set A Break Point In A Razor View

Nov 11, 2010

I can't seem to figure out how to set a breakpoint in a Razor view. I understand why that might seem a little weird and may be difficult since a cshtml file is a combination of html and then c# code, but I can step into it. The ability to step into it makes it seem like I should be able to set a breakpoint. Am I missing how to do this or is this not possible in the RC? If not any plans to add this before RTM or in the future?

View 3 Replies

Web Forms :: Add A New And Point It To The Master Page

Aug 9, 2010

The normal order for creating a web site is to creating a master page, then add a new web form and point it to the master page. However, I created my web form first, then created the master page. I am using 2008 express.

View 4 Replies

Installation :: Break Point Is Not Working?

Oct 9, 2010

I am using Visual Studio 2005 with Windows 7. The Problem is when i start debugging it doesn't stops at Break Points.

Debug = "True" in web.config

View 1 Replies

Does The Response.Redirect Hit The Break Point

Jun 9, 2010

My code does a response.redirect.

I noticed that while debugging. I had a break point on the page_Load but when it did the response.redirect and came to this page it did not hit the break point.

View 2 Replies







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