Forum; I am a newbie working out a bit of code. I would like to know the best way to use separate .cs files containing other classes and functions. As an example of a basic func
One class per .cs file is a good rule to follow.
I would not separate page specific functionality into separate .cs files unless you plan to encapsulate into a reusable class.
Edit:
Put the clear function in the button's OnClick event. No reason to separate this out.
.aspx file:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SimpleWebTest._Default" %>
Untitled Page
.cs file
using System;
namespace SimpleWebTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) { }
protected void ClearButton_Click(object sender, EventArgs e)
{
using (ComplexOperationThingy cot = new ComplexOperationThingy())
{
cot.DoSomethingComplex();
}
}
}
}
ComplexOperationThingy.cs:
using System;
namespace SimpleWebTest
{
public class ComplexOperationThingy
{
ComplexOperationThingy() { }
public void DoSomethingComplex()
{
//Do your complex operation.
}
}
}