"If You Can Dream It, We Can Build It"
Let us help your dream come true in web and multimedia design and development to open the doors to the digital world.
ASP.NET and C# (C sharp) Help
There are many online help resources for .NET using the Visual Studio tool. This question and answer is mainly focus on problems arrive when you develop .NET web application using Macromedia Dreamweaver.
Question: How to use C# (C sharp) classes? I am using ASP.NET with C#.
Answer: If you are using the Visual Studio it is just a matter of few clicks and hard work is done for you. If you are not using the tool you have to do all the hard work. But it is simple and at the end of the day you know exactly how it works.
Step 1: Simply create you C# (C sharp) class file. This is the sample structure of a simple class file.
//import C sharp system classes.
using System;
using System.Collections;
//namespace name
namespace MyNamespace
{
//class name
public class MyClass
{
//Variable declaration
public const string USER_TABLE = "Users";
//empty constructor (in this eample)
public Tool(){}
//sample method…
public bool YearValidate(string str)
{
try
{
int i = Convert.ToInt32(str);
if (i >= 1900)
return true;
return false;
}catch
{
return false;
}
}
}
}
Save the file as MyClass.cs
Step 2: Compile the C# (C sharp) file
You can create a bat file which will save lot of time you spend typing.
Line1:
D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc.exe /t:library /debug /out:class.dll *.cs /r:System.dll /r:System.Web.dll /r:System.Data.dll /r:System.Xml.dll
Line 2:
pause
Type line 1 and line 2 in text pad (without typing “line1” and “line 2”) as it is. You can change the “out.class” any of the names you like with the .class extension.
Fix if there are errors on you c sharp coding and recompile until it is error free. (First time the .class file will not be created until your c sharp code is error free.)
Step 3: Copy the .class file to a folder name “bin” in the root directory. Remember to create a bin folder if it does not exist in the root directory and bin folder should be in the root directory.
Step 4: Use your methods in the class file in you code behind file.
|