班级结构确认

时间:2012-06-18 08:59:49

标签: c# c#-4.0

我有这个类文件调用 SMSHelper.cs 首先我只是想知道我的书面结构是正确的还是错的?(我的班级文件名也是SMSHelper.cs& my first class also你可以在这里看到SMSHelper代码。)。

基本上我在同一个文件中有3个类。一个类与文件名同名。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;


namespace SMSBase.SMSFunction
{
public class SMSHelper : DotNetNuke.Entities.Modules.PortalModuleBase
{
 // Some Code here 
 // Return Something here
}
 public class Validator
   {
    public bool IsValidate(string Item)
    { 
    // Some Code Here Not return anything

 }

  public class HuntingDate
     {
    //Implementation & Constructor here.. Return Something
    }

    }

}

3 个答案:

答案 0 :(得分:1)

您的班级结构没有错(除了一个缺少的括号)。并且无论您的班级名称和文件名是否相同。您可以访问和初始化类对象......

SMSBase.SMSFunction.SMSHelper objSMSHelper = new SMSBase.SMSFunction.SMSHelper();

SMSBase.SMSFunction.Validator objValidator = new SMSBase.SMSFunction.Validator();

SMSBase.SMSFunction.HuntingDate objHuntingDate = new SMSBase.SMSFunction.HuntingDate();

这个SMSBase.SMSFunction是您的命名空间...您可以通过命名空间访问类,或者在类标题中包含此命名空间,如

using SMSBase.SMSFunction

答案 1 :(得分:0)

打开右括号时出现问题:

namespace SMSBase.SMSFunction 
{ 
public class SMSHelper : DotNetNuke.Entities.Modules.PortalModuleBase 
{  // Some Code here   // Return Something here 
}  
public class Validator    
{     
public bool IsValidate(string Item)    
 {      // Some Code Here Not return anything 

 }
}   
 public class HuntingDate     
 {     //Implementation & Constructor here.. Return Something   
 }      

 } 

如果这就是你的要求。

答案 2 :(得分:0)

是的Talha,说有一个支架丢失了。试着把它放进去。

当我们想要调用类名时,最好使用“namespace.ClassName”格式调用,这样可以使编译器清晰。