I have programmed in c++ before and created classes and structs and include files. But for some reason when I do this in C# i can not call the classes, functions, or structures I have created in the included file. Errrrr what am i missing. I have tried to follow examples but I must be totally clueless because nothing is working. You are going to ask for a code sample but a general answer would do just great if appropriate.
Thanks for the reply.
class help please set me straight
Page 1 of 113 Replies - 2513 Views - Last Post: 30 September 2005 - 08:10 PM
Replies To: class help please set me straight
#2
Re: class help please set me straight
Posted 29 September 2005 - 07:52 PM
Welcome to dream.in.code chasboi, can you post your code so we can take a look. Thanks!!
#3
Re: class help please set me straight
Posted 29 September 2005 - 07:54 PM
C# is not compiled the same way as c++; in C++, seperate header files and source files are all brought together in the order you include them to create a body of code.
In C#, you can have multiple source files for the sake of organization, but there are no header files. C# is pre-arranged into one body of code and then compiled (thus order of declaration is irrelevant, eliminating the need for function prototypes and headers and general).
Classes are not quite used in the same way as in C++; classes in C# function much more like classes in java, if you are familiar with that.
In C#, you can have multiple source files for the sake of organization, but there are no header files. C# is pre-arranged into one body of code and then compiled (thus order of declaration is irrelevant, eliminating the need for function prototypes and headers and general).
Classes are not quite used in the same way as in C++; classes in C# function much more like classes in java, if you are familiar with that.
#4
Re: class help please set me straight
Posted 29 September 2005 - 08:14 PM
CODE
Class Peronal_Info_Validator()
.........
.........
Public EMail_Validator(string emailAddress)
{
// validate email via regular expression and other criteria
}
Thanks for the reply. I have been going nuts about this.
Class Peronal_Info_Validator()
.........
.........
Public EMail_Validator(string emailAddress)
{
// validate email via regular expression and other criteria
}
Thanks for the reply. I have been going nuts about this.
This post has been edited by chasboi: 29 September 2005 - 08:15 PM
#5
Re: class help please set me straight
Posted 29 September 2005 - 08:19 PM
I'm assuming Email_Validator() is intendend as a function as part of the above class?
In that case, you need to remember to have a function type with it:
public void/bool/int/char/whatever EMail_Validator(string emailAddress)
{
//ladedadeda
return whatever_you_need_to;
}
In that case, you need to remember to have a function type with it:
public void/bool/int/char/whatever EMail_Validator(string emailAddress)
{
//ladedadeda
return whatever_you_need_to;
}
#6
Re: class help please set me straight
Posted 29 September 2005 - 10:45 PM
thanks Videege
I should have finished the function
public bool Email_validator(string emailAddress)
{
latada diddy dah
}
I want to use the functions in this class on multiple pages and in mmultiple applications but am running into a perverbial wall on the execution of the functions in the class.
Thanks for the help.
I should have finished the function
public bool Email_validator(string emailAddress)
{
latada diddy dah
}
I want to use the functions in this class on multiple pages and in mmultiple applications but am running into a perverbial wall on the execution of the functions in the class.
Thanks for the help.
#7
Re: class help please set me straight
Posted 30 September 2005 - 05:51 AM
Are you getting any errors? Or is the class just not available? Can you post
- The section of the file hwere you are specifying libraries, namespaces, and includes.
- The section where you instantiate an instance of the class
- Any errors you get upon compilation or instantiation.
#8
Re: class help please set me straight
Posted 30 September 2005 - 06:29 AM
Thanks for the reply Amadeus
I have tried to just call the function from the current page by passing the information to it. I have tried to import the class that the functions are in. I am not understanding how to do it obviously. I know this seems a little vauge but this is how my thinking is getting cloudy about the whole thing. The purpose is to validate form data. The function works if it is included in the page the form data is on but I want to use this for other programms and other forms in this app as well. I would appreciate an example in how to instantiate an instance of the function from its class. There is no inheratence.
Thank you for the reply.
I have tried to just call the function from the current page by passing the information to it. I have tried to import the class that the functions are in. I am not understanding how to do it obviously. I know this seems a little vauge but this is how my thinking is getting cloudy about the whole thing. The purpose is to validate form data. The function works if it is included in the page the form data is on but I want to use this for other programms and other forms in this app as well. I would appreciate an example in how to instantiate an instance of the function from its class. There is no inheratence.
Thank you for the reply.
#9
Re: class help please set me straight
Posted 30 September 2005 - 08:02 AM
To be honest, I'm not sure I understand the problem. Are you referring to how to include a separate file into a C# project executable? If so, then you do not include in the same manner which you would use with C++. C# compiles all CS files into one executable. If you are using the Visual Studio IDE, simply putting all the .cs files in one project will compile them all together, and make each one available to the others. If you are using a command line compiler, you simply specify all .cs files to compile into one project.
here and here provide examples of using the command line compiler syntax.
There is no specific "include" syntax...you compile them together...for example. the file I have below is Class1.cs
and then Class2.cs
Note I have not included Class2.cs in Class1.cs, but I can instantiate an instance and access it's methods, simply by compiling them together.
Please let me know if I've misunderstood the problem.
here and here provide examples of using the command line compiler syntax.
There is no specific "include" syntax...you compile them together...for example. the file I have below is Class1.cs
using System;
namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
int x = 100;
int y = 200;
Class2 c2 = new Class2();
c2.C2Display(x,y);
Console.ReadLine();
}
}
}
and then Class2.cs
using System;
public class Class2
{
public Class2()
{
}
public void C2Display(int x, int y)
{
Console.WriteLine("The coordinates are {0} and{1}\n", x,y);
}
}
Note I have not included Class2.cs in Class1.cs, but I can instantiate an instance and access it's methods, simply by compiling them together.
Please let me know if I've misunderstood the problem.
#10
Re: class help please set me straight
Posted 30 September 2005 - 09:29 AM
Amadeus
I was a little confused by this example. It mentioned to import the file so you can use the class's functions. I understand what I was doing wrogn thanks for the help. Thanks a ton. This is going to help.
I was a little confused by this example. It mentioned to import the file so you can use the class's functions. I understand what I was doing wrogn thanks for the help. Thanks a ton. This is going to help.
#11
Re: class help please set me straight
Posted 30 September 2005 - 09:45 AM
Amadeus
I was also reading the the "this" could be used as well. I assume it is in the same manner as the new Class2 c2 = new Class2(); but it would and could be used like this.Class2.C2Display(x,y);. I think that is how it would be used if I am correct in my understanding from your previous reply.
Thanks again for helping me much appreciated.
I was also reading the the "this" could be used as well. I assume it is in the same manner as the new Class2 c2 = new Class2(); but it would and could be used like this.Class2.C2Display(x,y);. I think that is how it would be used if I am correct in my understanding from your previous reply.
Thanks again for helping me much appreciated.
#12
Re: class help please set me straight
Posted 30 September 2005 - 10:11 AM
The this keyword is essentially a pointer that refers to the current instance of any class you may be using. It can be used to access member methods of that class from within methods, constructors, etc... The link provides an example.
#13
Re: class help please set me straight
Posted 30 September 2005 - 04:06 PM
chasboi, on Sep 30 2005, 10:26 AM, said:
Amadeus
I was a little confused by this example. It mentioned to import the file so you can use the class's functions. I understand what I was doing wrogn thanks for the help. Thanks a ton. This is going to help.
I was a little confused by this example. It mentioned to import the file so you can use the class's functions. I understand what I was doing wrogn thanks for the help. Thanks a ton. This is going to help.
As Amadeus pointed out (and me as well earlier
If you're using MSVC# v whatever, simply putting all your files into the same project will compile them all together.
#14
Re: class help please set me straight
Posted 30 September 2005 - 08:10 PM
Thanks again. I really appreciate the help and will take all of what you mentioned into consideration in my next adventures in VS2003.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|