• 0

Hey how do I do this?


Question

12 answers to this question

Recommended Posts

  • 0

Thanks, I am a pretty new to C#...  so what's easy to you I don't know well yet. :/

 

Another question, if any of you would kindly answer.

 

 

For a public void method say public void xyz() it wants to public void xyz( object abc) as a method. This method casts the object as an abc and adds it to the abc collection.

 

 

How do I go about do this?

So something like:

 

List<abcObj> abcObjs = new List<abcObj>();

private void addToAbcObj(object myObj)
{
  abcObjs.Add((abcObj)myObj);
}
Link to comment
Share on other sites

  • 0

Do you know what a constructor is? Do you know what class properties are? Do you know how to set the value of a property? How much experience do you have with programming?

 

This is a pretty simply thing to do; please post what you've tried / know so far and then ask some more in depth questions about what exactly you're not understanding or otherwise having trouble with.

Link to comment
Share on other sites

  • 0

Public default constructor method that initializes properties about with a the CurrentDate and 2 Zeroes?

You mean something like this:

 

import java.util.Date;

class MyApp {

    public static void main ( String[] args ) {
        DateStore currentDate = new DateStore ();
        System.out.println ( currentDate.getDate () );
    }    
}

class DateStore {

    private Date date;    
    
    public DateStore () {
        this.date = new Date ();
    }

    public String getDate () {
        return date.toString ();
    }
}
$ javac class.java
$ java MyApp
Sun Sep 21 20:43:34 BST 2014

 

Not sure what you mean by "2 Zeroes".

  • Like 1
Link to comment
Share on other sites

  • 0

C#

 

We need more description what you're class looks like.

 

You can use DateTime.Now to get the current date and assign it to a class member, and assuming that you want the "zeroes" to be assigned to integer variables, just do something like this:

myInt = 0;
Link to comment
Share on other sites

  • 0
public class MyClass
{
	public int Integer1 { get; set; }
	public int Integer2 { get; set; }
	public DateTime DateTime1 { get; set; }

	public MyClass()
	{
		this.Integer1 = 0;
		this.Integer2 = 0;
		this.DateTime1 = DateTime.Now;
	}
}

C#

Link to comment
Share on other sites

  • 0

Thanks, I am a pretty new to C#...  so what's easy to you I don't know well yet. :/

 

Another question, if any of you would kindly answer.

 

 

For a public void method say public void xyz() it wants to public void xyz( object abc) as a method. This method casts the object as an abc and adds it to the abc collection.

 

 

How do I go about do this?

Link to comment
Share on other sites

  • 0

That's more cryptic than your first request.

 

Yep; sounds like someone trying to get us to do their homework to me rolleyes.gif

 

OP, if you're genuinely just trying to learn, that's fine, I'm happy to help, but I'm not convinced that's the case, and you're not framing your questions well. For this last question of yours, post the code you've got so far and then maybe we can demonstrate and explain how best to achieve what you're after.

  • Like 2
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.