Maximizing ASP.NET Real World, Object-Oriented Development [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Maximizing ASP.NET Real World, Object-Oriented Development [Electronic resources] - نسخه متنی

Jeffrey Putz

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید











Static (Shared) Members


There are times when you don't need an entire class to perform some action. If you need a method that, for example, redirects a user to a specific URL, instantiating an entire class would be overkill. That's where static methods come in!

Marking a method static (or Shared in VB) means that you don't have to create an instance of the containing class in order to use it. A redirect method that you might use across your entire application might look like the method in Listing 2.14.

Listing 2.14. A static method

C#


public class MyMethods
{
public static void SpecialRedirect()
{
Response.Redirect("somepage.aspx");
}
}

VB.NET


Public Class MyMethods
Public Shared Sub SpecialRedirect()
Response.Redirect("somepage.aspx")
End Sub
End Class

Calling this method is just a matter of specifying the class name itself, followed by the method name:


MyMethods.SpecialRedirect()

I find that in almost every large project, there are little pieces of functionality that don't really fit anywhere and that certainly don't merit their own class. Inevitably, I end up with a class called Utility with several static methods like the previous one.


/ 171