Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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
 
Old April 8th, 2012, 10:45 AM
Registered User
 
Join Date: Nov 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Use constants in ASP.NET 3.5

I am regular programmer in traditional ASP, but now turning to program in ASP.NET 3.5. My requirement is defining few constants about 20 of them of different types:
Strings, integers, datetime etc. In traditional ASP, I used to define them in a single file
Example abc.asp
In each application file, I used to include the abc.asp file as
<!--#include file="nsns5DBCONN.asp"-->
and use the constants.

Dim dtdldate,inthseries, strvenue
dtdldate= #6-5-2010 4:00:00 PM#
inthseries=8000
strvenue=”zzzzzzzzz”

I want to do the same in ASP.NET 3.5. I created a file myconstants.cs
In App_code folder.

public class myconstants
{
public myconstants()
{

}
}

Please let me know how proceed from now.
I want to know how to define the above 3 different types of constants
And how to use them in individual application aspx files. I want the code in both C# and VB.
 
Old April 8th, 2012, 11:00 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Since this is not directly related to my book, please post questions like these in a more general ASP.NET category from this list: http://p2p.wrox.com/asp-net-asp-12/ This way, you'll attract more viewers.

That said, your code is almost done; just define the constants in your class:

Code:
using System;
public class MyConstants
{
  public const int    inthseries=8000;
  public const string strvenue = "zzzzzzzzz";
}
You then use them in your code as follows:

string whatever = MyConstants.strvenue;

You can't declare DateTime as a constant so, depending on how you need it, you need to look at alternatives.

Quote:
I want the code in both C# and VB.
Yes sir. Right away sir. Anything else sir? Can I get you some coffee?

In other words, this is not how it works. We're here to help you but we're not your servants. This is basic code so you should be able to convert from C# to VB yourself. If not, helpful converters are available: http://converter.telerik.com

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Constants: Where do they go? DragonLEG BOOK: Beginning ASP.NET 4 : in C# and VB 1 June 11th, 2011 02:02 PM
Changing Constants within a session mat41 Classic ASP Basics 2 August 27th, 2009 12:11 AM
declaring constants and pointer constants proslambano BOOK: Ivor Horton's Beginning Visual C++ 2005 3 March 6th, 2007 03:32 PM
Constants in XSL austinf XSLT 2 August 29th, 2006 06:04 AM
DriveType constants fordrs3 Beginning VB 6 1 June 22nd, 2003 08:23 AM





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