|
Your Main method just needs to be in a class, thats what the error is saying. The compiler expected a class or struct etc. but it found a method, so it gave you the error.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Am practising on writing classes from an exercise that requires hardcoding values into a program.
Task requires
1. defining a class Pupil and a class Homework
2. Containing data for two sample Pupils and their homeworks(hardcoded in the program)
3. Lets the user enter the keywords to be checked for
4. Let the user request to see the homework data of a pupil
Hard coded data/values like
John Kay
67890
initial sentence ;= There was a tiny little.....
Words; = 200
keyword; = overwhelming
Woul really appreciate your thoughts on the approach
Angelinna
modified on Tuesday, May 20, 2008 9:59 PM
|
|
|
|
|
1 - I think you had this OK, just define classes
2 - Create two pupils and their homework in your static void main, and pass in the values
3 - Accept user input and then check your items to see if they match
4 - accept user input to select a pupil, and output the contents of their homework.
Is this a console app or a windows one ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
What i understand from reading all the posts is
You can't initiate
Homework Patr = new Pupil(); //Simply can't do that
Homework is different type and Pupil is different type
it is same as doing
string Patr = new int();
You must derive your Homework class from Pupil or take a object of Homework in Pupil
|
|
|
|
|
I think you're a bit confused on classes here - you need to do some serious research and study.
I'll try to help a little but I'm not doing it for you - I'm sure you wouldn't want me to!
Let's look at a Pupil class.
There's many ways to create a class, but I find the easiest is to have four sections (or regions - you can actually use this word in your code!).
1. Member variables - declare these as private so only the class itself can modify them.
2. Properties - public so they can be accessed outside of the class.
One benifit of the above two over a single public variable is the property get and set methods can alter/filter/validate the data. There a many others but this isn't supposed to be an article!
3. Methods - these actually do stuff with the data and if necessary return a value of any type needed.
4. Constructors - these are used to create an instance of your class.
This is an example Pupil class - see if you can follow what's happening. When you understand *EVERY* line you may be ready to attempt the task you've posted. This code won't work fully without some work and understanding from you as it references 2 other classes - Homework and PupilHomework . I'm leaving it up to you to create those, make them interact with the Pupil class, and add any neccesary enhancements to the Pupil class.
public class Pupil
{
#region Member Variables
private int m_ID;
private string m_Name;
private List<PupilHomework> m_HomeworkList;
private static int lastID = 0;
#endregion
#region Properties
public int ID
{
get { return m_ID; }
}
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
public List<PupilHomework> HomeworkList
{
get { return m_HomeworkList; }
}
#endregion
#region Methods
public void AddHomework(Homework homework)
{
m_HomeworkList.Add(new PupilHomework(homework.ID));
}
#endregion
#region Constructors
public Pupil(string name)
{
m_Name = name;
m_ID = ++lastID;
m_HomeworkList = new List<PupilHomework>();
}
#endregion
}
Dave
|
|
|
|
|
Thanks Dave. You have been most helpful
|
|
|
|
|
No problem. Post back if you have any more problems
Dave
|
|
|
|
|
When I used to code console apps for C++, my program could take runtime arguments, like
int main ()
{
return 0;
}
How can I do something similar to this in C#? I am running a windows form application, and when I tried static void Main(string open) it gave me an error saying it wasnt a proper place for program entry.
How can I accomplish this?
Thanks in advance.
|
|
|
|
|
That Asian Guy,
static void Main(string[] args)
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Wow that was easy. Thanks :P
|
|
|
|
|
Yeah, what he said, plus
static int Main ( string[] args )
{
return 0;
}
|
|
|
|
|
Ah, somebody as pedantic as I am about Main returning an int.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Vikram A Punathambekar wrote: as pedantic
If not moreso.
No reason not to and it's going to anyway, why not control it?
|
|
|
|
|
I am trying to set the following registration in my aspx so I can bind a wcf service to an AutoCompleteExtender:
]]>
However, the compiler returns the following error:
"The directive 'servicehost' is unknown"
I have added the following "using" directive to the codebehind:
using System.ServiceModel;
I have added servicehostingenvironment aspnetcompatibilityenabled="true" as a child element of system.servicemodel in Web.config.
What am I missing?
NOTE - This forum software automatically wraps the directive tag above with "CDATA"
|
|
|
|
|
Did you add a reference to System.ServiceModel?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
I am trying to return Count(*), cast to a String and assign the value to Label1.Text. I am a bit stuck on the C# syntax because I am new to C#. This is what my research has produced thus far:
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(ConnString))
{
//String newTagName = txtParm.Text;
int DOWcount = 0;
SqlCommand cmd = new SqlCommand("SELECT count(*)FROM RealTime WHERE DATEPART (d,CallStartTime) = DATEPART(d,getdate())", conn);
cmd.Parameters.Count;
conn.Open();
DOWcount = cmd.ExecuteNonQuery();
Label1.Text = DOWCount.ToString();
I know that I am not using the "cmd" correctly. Can anyone of the experts out there steer me in the right direction?
|
|
|
|
|
mreynol5 wrote: Can anyone of the experts out there steer me in the right direction?
No. No one knows how to do that. And if anyone did it certainly would not be Microsoft and they certainly would not document it.[^]
And you certainly would not be able to find the documentation using Google[^]
mreynol5 wrote: I am a bit stuck on the C# syntax because I am new to C#.
Ok, good luck
led mike
|
|
|
|
|
Change this:
DOWcount = cmd.ExecuteNonQuery();
to this:
DOWcount = (int)cmd.ExecuteScalar();
Hope that helps
|
|
|
|
|
Hi,
In part of my undo/redo system (for property value changing on certain component types which must be recreated) it would be very useful to create a copy instance. Now I have achieved this using the designated 'CreateInstance' method as provided by the type converter. My problem is understanding exactly how to get the propertyValues 'IDictionary' type object.
I have created the following method which works, but I wanted to know if anybody has any suggestions to improve this or perhaps if there is an easier way. I am worried that this approach may cause issues, would property descriptor attributes need to influence this process in some way?
protected object CreateInstanceCopy(PropertyDescriptor descriptor, object component)
{
PropertyDescriptorCollection propertyValues = descriptor.Converter.GetProperties(component);
Dictionary<propertydescriptor, object=""> values = new Dictionary<propertydescriptor, object="">();
foreach (PropertyDescriptor desc in propertyValues)
values.Add(desc, desc.GetValue(component));
...
return descriptor.Converter.CreateInstance(values);
}</propertydescriptor,></propertydescriptor,> Thanks,
Lea Hayes
|
|
|
|
|
hi...
i'm using crystal reports with C#. I'm using an ODBC connection for the report.
when trying to open the report from test machine it gives this window.
.........................................
Databse login .
.........................................
server name: .
DataBase: .
LoginID: .
password: .
.
integrated security (checkbox) .
.........................................
how can a reomve this window
|
|
|
|
|
shabonaa wrote: how can a reomve this window
Click the red 'X' in the upper right corner
led mike
|
|
|
|
|
Hey Shabonaa,
What you need to do is programatically set that in the page load or report load event using code behinds.
The only way I found to easily remove the window is to load the crytsal report in the code behind page and NOT in the .aspx
Does this make sense?
You should google "crystal reports c# programmatically" and sift around for something close to what you are doing.
-----------------------------------------------------------
"When I first saw it, I just thought that you really, really enjoyed programming in java." - Leslie Sanford
|
|
|
|
|
i'm using a windows application. not asp
|
|
|
|
|
hmmm. should still be doing it programmatically then.
you should still be loading up the report and passing logon credentials through the C# code. if not in a code behind, then in a class file. but you will have to do it that way.
You should google "crystal reports c# programmatically" and sift around for something close to what you are doing.
-----------------------------------------------------------
"When I first saw it, I just thought that you really, really enjoyed programming in java." - Leslie Sanford
modified on Tuesday, May 20, 2008 6:16 PM
|
|
|
|
|
You have to provide the login information (programmatically), even though you have done that in the Crystal Report designer.
|
|
|
|