Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 9th, 2006, 02: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;
        }
    }

  #2 (permalink)  
Old January 9th, 2006, 04: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

  #3 (permalink)  
Old January 11th, 2006, 01: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,407
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
  #4 (permalink)  
Old January 11th, 2006, 04: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
  #5 (permalink)  
Old January 13th, 2006, 10: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,407
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET STATIC PORT farsfar2 ASP.NET 2.0 Basics 2 November 25th, 2009 07: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 08:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.