class

  • Thread starter Thread starter selen
  • Start date Start date
S

selen

Hello;
I have little information about classes.First I ask you a book which one
explain classes
with details.Second Can you look the code where I am making wrong.

public static void ArrayList rolSil(Rol aRol)


{

rolIdSil(aRol.getRolId ());

int i=0;

ArrayList bagliRoller=aRol.getBagliRoller();

while (i<aRol.getBagliRoller().Count )

{

rolSil(bagliRoller);

}//while



}
..net gives error that : ";" is expected at rolsil.Also I have the another
method that
send parameter above code.It is:
public static void rolSil()

{

RolDb db=new RolDb ();

return db.rolSil(this);

}

This code calls roldb from another class.I want to make rolsil in Rol class
send yourself parameter
to method in RolDb this is the reason I wrote this.But it gives error.How
can I send Yourself.

Thanks.....
 
I am somewhat confused about what you are trying to accomplish

public static void ArrayList rolSil(Rol aRol)

....has two return types, you can't have both void AND ArrayList. If you
need more return types read up on ref, out and returning objects
containing all the types you want returned.

public static void rolSil()

....has void return type (which means you shouldn't return anything)
return db.rolSil(this); will therefore be illegal.

return db.rolSil(this);

....won't work because a static method has no 'this'

A static method is a method accessible to a class, but doesn't belong to
any particular object of the class.


public static void ArrayList rolSil(Rol aRol) // error, see above
{
rolIdSil(aRol.getRolId());

int i = 0;

ArrayList bagliRoller = aRol.getBagliRoller();

while(i < aRol.getBagliRoller().Count)
{
rolSil(bagliRoller); // recursive loop, not sure what you want to
accomplish
}
}

public static void rolSil() // error, return not allowed when using void
{
return db.rolSil(this); // error, see above, and static methods have no
'this'
}

If you could explain what you are trying to do in a bit more detail we
might give you some coding suggestions.
 
Thank you It is enough for me.My error is I used void and Arraylist.
is anybody know which books explain classes with more detail??

Thanks...
"Morten Wennevik" <[email protected]>, iletide sunu yazdi
I am somewhat confused about what you are trying to accomplish

public static void ArrayList rolSil(Rol aRol)

....has two return types, you can't have both void AND ArrayList. If you
need more return types read up on ref, out and returning objects
containing all the types you want returned.

public static void rolSil()

....has void return type (which means you shouldn't return anything)
return db.rolSil(this); will therefore be illegal.

return db.rolSil(this);

....won't work because a static method has no 'this'

A static method is a method accessible to a class, but doesn't belong to
any particular object of the class.


public static void ArrayList rolSil(Rol aRol) // error, see above
{
rolIdSil(aRol.getRolId());

int i = 0;

ArrayList bagliRoller = aRol.getBagliRoller();

while(i < aRol.getBagliRoller().Count)
{
rolSil(bagliRoller); // recursive loop, not sure what you want to
accomplish
}
}

public static void rolSil() // error, return not allowed when using void
{
return db.rolSil(this); // error, see above, and static methods have no
'this'
}

If you could explain what you are trying to do in a bit more detail we
might give you some coding suggestions.
 
selen said:
Thank you It is enough for me.My error is I used void and Arraylist.
is anybody know which books explain classes with more detail??

What exactly do you want to know about classes? Just about any C# book
or tutorial will take you through various different aspects of them.
 
When I use private,public ,static, void...
and Detail example...
for eample they tell Recursive programming and give us exmple fibonacci
series.I want to more
complicated examples.So i can understand when I must use recursive
programming.
 
Recursive methods are very powerful, but avoid to use it, because they can
be very dangerous.
Everything you can do without a recursion, do it without a recursion

selen said:
When I use private,public ,static, void...
and Detail example...
for eample they tell Recursive programming and give us exmple fibonacci
series.I want to more
complicated examples.So i can understand when I must use recursive
programming.
 
As an example of using recursive loops is finding a file in a directory.

(Pseudocodish)

if(FindFile(rootDirectory, missingFile))
//file is found
else
//file not found

private bool FindFile(Directory dir, string filename)
{
// If file is in this directory we have found it and start backtracking
through the loop
if(File.Exists(dir + filename))
return true;

// File was not in this directory, does it have subdirectories?
if(dir.HasDirectories)
{
// Call FindFile on each subdirectory
foreach(Directory d in dir.subDirectories)
{
// If FindFile ever reaches the end it will return null, no file found
if(FindFile(d, filename))
{
// if not null, file is found in d
// which means the first if sentence in the bottom of the loop
// returned dir + filename
// so start returning the location to each parent caller
return true;
}
}
}
return false;
}

This will dig deeper into every subdirectory until it finds the file or
all directories have been checked. Then it will keep returning true to
every recursive caller of FindFile until in the end, our own call to
FindFile receives true or false;
 
Thanks everyone...
Zürcher Why are you saying it is dangerous.How can I make everythig withour
recursive.
For example Morten's example..........
"Morten Wennevik" <[email protected]>, iletide sunu yazdi
As an example of using recursive loops is finding a file in a directory.

(Pseudocodish)

if(FindFile(rootDirectory, missingFile))
//file is found
else
//file not found

private bool FindFile(Directory dir, string filename)
{
// If file is in this directory we have found it and start backtracking
through the loop
if(File.Exists(dir + filename))
return true;

// File was not in this directory, does it have subdirectories?
if(dir.HasDirectories)
{
// Call FindFile on each subdirectory
foreach(Directory d in dir.subDirectories)
{
// If FindFile ever reaches the end it will return null, no file found
if(FindFile(d, filename))
{
// if not null, file is found in d
// which means the first if sentence in the bottom of the loop
// returned dir + filename
// so start returning the location to each parent caller
return true;
}
}
}
return false;
}

This will dig deeper into every subdirectory until it finds the file or
all directories have been checked. Then it will keep returning true to
every recursive caller of FindFile until in the end, our own call to
FindFile receives true or false;
 
selen said:
Thanks everyone...
Zürcher Why are you saying it is dangerous.

Because it eats up stack space, which is fairly limited - if you write
code which will recurse by some amount which is will depend on an
environment you don't know about, you run a significant risk of blowing
your stack.
How can I make everythig withour
recursive.
For example Morten's example..........

You would keep a list of some description (Queue, Stack, ArrayList,
whatever) of directories you still need to look through. Your initial
condition becomes the list having one entry, and your termination
condition becomes the list being empty, or the file being found:

Still pseudocode:

bool FindFile (Directory dir, string filename)
{
Queue queue = new Queue();
queue.Add(dir);

while (queue.Count != 0)
{
Directory dir = (Directory) queue.Dequeue();

// Got it?
if (File.Exists (dir+filename))
return true;

foreach (Directory d in dir.GetDirectories())
{
queue.Add(d);
}
}
// Exhausted the possibilities
return false;
}
 
Back
Top