Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 9th, 2006, 01:50 PM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default static Class in ASP

Hi, I want to make a static class for my special function like MD5String. I'm pretty sure of my syntaxe but the compilator says on then line (public static class CMD5) : "c:\inetpub\wwwroot\HelloWorld\CMD5.cs(8): Le modificateur 'static' n'est pas valide pour cet élément" or in english : "The modificator 'static' is not valide for this element"

    public static class CMD5
    {
        public static string MD5String(string password)
        {
            MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvi der();
            byte[] bs = Encoding.UTF8.GetBytes(password);
            bs = x.ComputeHash(bs);
            StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in bs)
            {
                s.Append(b.ToString("x2").ToLower());
            }
            password = s.ToString();
            return password;
        }
    }

Reply With Quote
  #2 (permalink)  
Old January 9th, 2006, 03:27 PM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The answer is simple I needed to use
public sealed class CMD5
instead of
public static class CMD5

Reply With Quote
  #3 (permalink)  
Old January 11th, 2006, 12:30 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Note that the change you made wasn't really a 'fix' per se.

You can not use the modifier "static" on a class. You could say that technically, all classes are static, because they are type definitions. You can (as you did) make a METHOD static so you can reference by type without the need for an object instance.

The "sealed" modifier means that your class can not be inherited.

-Peter
Reply With Quote
  #4 (permalink)  
Old January 11th, 2006, 03:26 PM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have taken this exemple directly from MSDN:

public static class TemperatureConverter
{
    public static double CelsiusToFahrenheit(string temperatureCelsius)
    {
        // Convert argument to double for calculations.
        double celsius = System.Double.Parse(temperatureCelsius);

        // Convert Celsius to Fahrenheit.
        double fahrenheit = (celsius * 9 / 5) + 32;

        return fahrenheit;
    }

    public static double FahrenheitToCelsius(string temperatureFahrenheit)
    {
        // Convert argument to double for calculations.
        double fahrenheit = System.Double.Parse(temperatureFahrenheit);

        // Convert Fahrenheit to Celsius.
        double celsius = (fahrenheit - 32) * 5 / 9;

        return celsius;
    }
}

Why can they maked the class static? Is it because it's in ASP.NET2.0?

And I fogot;) Thanks
Reply With Quote
  #5 (permalink)  
Old January 13th, 2006, 09:58 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Here's the current documentation on the "class" keyword:

http://msdn.microsoft.com/library/en...eclasstype.asp

From the docs:
"modifiers (Optional)
    The allowed modifiers are new, abstract, sealed, and the four access modifiers."

I can't find anything regarding using the 'static' keyword but admittedly, I can't seem to get at the 2.0 msdn docs. I must not be awake yet.

-Peter
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET STATIC PORT farsfar2 ASP.NET 2.0 Basics 2 November 25th, 2009 06:48 AM
Using logging class as a static class punitw General .NET 0 August 14th, 2008 03:03 AM
non-static reports to static html files miamikk ASP.NET 2.0 Basics 0 June 4th, 2007 01:48 PM
static field with class instance prakash.suthar Java Basics 2 July 3rd, 2006 01:41 AM
who destroy static variables(no instance of class) MikoMax J2EE 1 March 31st, 2004 07:01 AM



All times are GMT -4. The time now is 02:06 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.