|
The docs on System.Array isn't exactly a needle in a haystack.
CaptainSeeSharp wrote: I don't have time to read through moutains of documentation
Then you don't have time to write code either.
|
|
|
|
|
the link I provided was the first result for "MSDN online" when I entered "array class" in Visual's search page. I never saw a haystack, it took me all of 10 seconds to get it.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I have been searching all over for an answer, but I have fallen back to asking the programming geniuses that frequent this site.
I am looking into a way to call different methods within a class. The problems are, in the class there are lots of methods and many of the methods are similar in function. So I am looking for a way to put the methods in a hierarchy within the class, but namespace can't be called within a class.
Hopeing for the class to resemble something like:
namespace IEWindow
{
public class Main
{
public void Method()
{
}
public ... NavigationBar
{
public void Method()
{
}
public ... Forward
{
public bool Method()
{
}
}
public ... Back
{
}
public ... AddressBar
{
}
}
}
}
*Note, in reality this will contain as many as a few hundred methods;
and to be used like
IEWindow.Main IEWin = new IEWindow.Main();
IEWin.Method();
IEWin.NavigationBar.Method();
bool g = IEWin.NavigationBar.Forward.Method()
Any help, even a statement like 'This is impossible, but thanks for humoring me', would be greatly appreciated.
|
|
|
|
|
I'm not sure what you're describing.
In C# you can declare classes within classes, but you can't declare methods within methods.
|
|
|
|
|
not really a method within a method, just a way to create a hierarchy that contains methods within a class. With namespace i know you can create exactly what I am looking for, but it doesn't work within a class. I can do without this ability, but that would mean 100's of methods would be sitting in my class without any organization, meaning the method names would end up being unnecessarily complicated and hard to distinguish one group of methods from another.
I would just rather be calling:
bool g = IEWin.NavigationBar.Forward.Method()
instead of:
bool g = IEWin.NavigationBar_Forward_Method()
|
|
|
|
|
Then you may want to declare classes within classes, but agregation may be a better technique. You may also want to use partial classes to help manage the code.
|
|
|
|
|
If you are using. Net 3.5 you may want to look at the function and action delegates
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
MafiaMoe wrote: in reality this will contain as many as a few hundred methods;
I'm not sure what reality you are living. A few hundred methods?!?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
My reality is a little strange...
The program creates a .dll that has a single class and usually around 10 to 20 methods, but could be in the hundreds depending on how it is used.
|
|
|
|
|
Hundreds of methods?? I'd scrap the library and use something that is better organized and not so convoluted.
|
|
|
|
|
MafiaMoe wrote: IEWin.NavigationBar.Method();
bool g = IEWin.NavigationBar.Forward.Method();
for this to work, NavigationBar must be:
- a public member or property of IEWindow;
- an instance of some other class that has:
- a public Method() method.
- a public member or property called Forward, which is itself an instance of some other class that has a Method() method.
Conclusion: you build a hierarchy of classes, and provide either data members holding, or properties returning, an instance of some child class (which could or could not be an inner class, your choice). So you could do hundreds of different operations on IEWin although IEWindow itself does not have to offer hundreds of methods, it all becomes one big hierarchy (or tree).
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Add(String GUID, String name, NetProtocol net, String ServerName, Int32 port, String UserName, String Password)
that is a method, but now i need to check all variables if are null or empty. If any one does not match, it would throw expection.
I don't like too many if statemnts, is it possible to put everything in one If line?
|
|
|
|
|
Saksida Bojan wrote: is it possible to put everything in one If line?
Have you forgotten what you learned while reading your first C# book? you can build complex expressions, e.g. using the logical AND and OR operators.
However, the user of your class/method won't like it when your method gives a single exception saying "some parameter is wrong". You really should use one IF per parameter as a minimum.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
What makes you think he ever read a book ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
That was a suggestion in disguise.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Is it something like this?
if (name == null || name.Equals("") || ServerName == null || name.Equals(""))
Yes i have read C# book, but quite while ago. And once i have tried using with many OR operators, i didn't got the desired results
Luc Pattyn wrote:
However, the user of your class/method won't like it when your method gives a single exception saying "some parameter is wrong". You really should use one IF per parameter as a minimum.
This class isn't part of GUI.
|
|
|
|
|
seems OK, why don't you try it?
also have a look at String.IsNullOrEmpty(), that could be a more compact solution.
Saksida Bojan wrote: This class isn't part of GUI.
That's besides the point; the user of your class or method, i.e. the person writing the code that is going to use them (even if it is you), may appreciate getting a specific error message.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Also, if you're writing C# (and not Java) just test string equality with the == operator; there's no need to call Equals directly.
Plus, it's a little more efficient to test for an empty string by checking its Length.
And, as Luc said, IsNullOrEmpty is the preferred way to check this.
Personally, I check each separately so I can give more detailed Exceptions.
|
|
|
|
|
Saksida Bojan wrote:
Yes i have read C# book, but quite while ago. And once i have tried using with many OR operators, i didn't got the desired results
Perhaps you should read it again ?
Saksida Bojan wrote: This class isn't part of GUI.
What is the point of the class reporting if the input is unacceptable, unless it asks the user to correct it ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Saksida Bojan wrote: I don't like too many if statemnts, is it possible to put everything in one If line?
Why don't you ? Let me explain something to you. Writing code that a computer can understand, is easy. One of the worst things about outsourced code, is how illegible it is to humans. Do the poor person who is going to maintain this code in the future a favour, and think about writing legible code, rather than your personal preferences.
Also, how can you provide a detailed error message if all your if statement knows is that one of the parameters is invalid ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
|
By web app, you mean a windows app that works with the web ? Your app is not ASP.NET, right ?
ninjatruck wrote: I am new to C#,
This is an odd task for someone who is 'new to C#'. How new is new ? What other languages do you know ? Why are you writing this right now ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Well my plan is to use this as part of the code behind class for an ASP.NET website.
I know c++, though I'm not very experienced with that either. I'm writing this now to help a friend who wants this for work. The program will read a .csv, and check URLs based on what it reads. I have everything else working great, but checking the URL isn't working correctly. I've only been working with c# for about a month at this point.
|
|
|
|
|
ninjatruck wrote: Well my plan is to use this as part of the code behind class for an ASP.NET website.
Why would an ASP.NET site be checking if other sites are valid ?
ninjatruck wrote: I know c++, though I'm not very experienced with that either. I'm writing this now to help a friend who wants this for work.
Wait - you don't really know C# or C++, or any other language, but you're writing this to help a friend, who knows so little about programming that they are asking for help from a beginner, yet they are writing code for their job ?
ninjatruck wrote: The program will read a .csv, and check URLs based on what it reads. I have everything else working great, but checking the URL isn't working correctly. I've only been working with c# for about a month at this point.
For someone who has been working with C# for a month to try to write code like this, is insane. You're not learning C# really, you're learning enough syntax to try to use some objects in the .NET framework, without really understand what is going on.
Have you checked what exception is thrown when you go to a URL you expect is valid ? Perhaps the exception type is different.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I hadn't checked what exception was thrown. Thanks for the idea.
Honestly I didn't realize this was such a complicated task when I said I would help.
|
|
|
|