|
string str = new string(char[] value);
Toby Russell
|
|
|
|
|
Dear all,
i would like to know is it possible to use function with optional parameter or is there any better way of doing so.
thnk you
imaran khan
|
|
|
|
|
There are no "default" parameters like there are in C++.
However, you can achieve the same thing with a simple overload.
public void myFunction(int requiredArg){
myFunction(requiredArg, false);
}
public void myFunction(int requiredArg, bool optionalArg){
}
|
|
|
|
|
thank for reply
Actually i have one to fifteen parameter and fuction must take one parameter and rest depending on user choice program will pass.
how to do that
please help
thanks
imaran khan
|
|
|
|
|
Could you explain it a bit more please?
You could cast all the parameters to an object[] and then cast them back inside of the function, giving default values to the ones that the user didn't specify.
|
|
|
|
|
thnks for reply.
let me explaine the scenario. there is 15 field say suppose
customer , category ,subcategory etc ..
User select category or subcategory or customer or any thing
depending on selection ,value from corresponding master is populated. now i select values from dropdownlistbox and pass to fuction.
Now my problem is user may select only customer or category or subcategory. may select combination or all.
please guide.
thanks
imran khan
|
|
|
|
|
Might be worth using Nullable Types and simply leaving all non selected values as Null. Then check for the values that aren't null and proceed accordingly. That way you keep your function footprint and it's strongly typed.
Alternatively, you could use an argument object / struct containing the parameters so you only have to change your object, rather than breaking the function footrpint with each change, just watch for mapping breaks.
T
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
If the parameters are of the same type, you can use the params keyword:
public void SomeMethod(string firstParameter, params int[] theOtherParameters)
This method can be called with any number of parameters following the first parameter:
SomeMethod("count", 1, 2, 3);<br />
SomeMethod("answer", 42);
If you want an upper limit, you have to check the lenght of the params array in the method.
---
single minded; short sighted; long gone;
|
|
|
|
|
As Guffa mentioned, if the parameters are all of the same type you can use the params keyword. (You could also use params object[], but you loose the type safety.)
Another option is to use either an enum to specify related groups of options or create a class that holds the arguments (parameters) and pass that class. The enum is similar to the
String.Compare(String, String, StringComparison)[^] method while the args class is how the .NET event handling does things (through the EventArgs[^](or derived) class.)
|
|
|
|
|
hi there,
I'm currently building a webservice and I've got three questions: is there anything special i need to know about the returned xml? right now, I just return an object (for expample an instance of my Vehicle class) from the WebMethod and this looks fine to me.
The second question is, if I use the automated xml serialization with a class which is derived from a base class I defined (e.g. I've got a Car class which derives from the Vehicle class), the properties of the baseclass are not serialized. Properties of the derived class look fine. Why is that?
Last but not least: What is the correct way to return an error from a WebMethod if, for example the expected parameters are invalid or an exception occured.
thanks a lot!
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
The answer to question 1 is that you don't pass the object. Whenever you pass something back from a web-service, you are passing based on a contract. This is important. Basically, you say that your data will look like this, and the SOAP message will contain a representation of that object.
2. Is the base class marked as Serializable as well?
3. It really depends on what you want to achieve. It is perfectly legitimate to throw an exception back from a web-service, but be aware that the exception you get back will not be the exception you threw. (Go on, try it - you'll get a SOAP exception back).
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
hey pete,
thanks for your reply. as for 1: i understand that my object makes up the contract you've mentioned (the structure of the returned xml). So I believe I as long as I don't change my returned object, everything should work fine for my clients. how would you do it? whats the best practise. in the article of chris (http://www.codeproject.com/cs/webservices/myservice.asp[^]), he's doing the same and the documentation doesn't really give me any useful information.
as for 2: yes, it has the SerializableAttribute .
3: I'd like to tell my clients, well, if you have no permission, you'll get this type of response, if you passed in invalid arguments, you'll get that type of exception. my english is not so good, I hope you understand what I mean.
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
Hi,
I have a textbox control whose character (actually a number) length should be 11. I desire to enter a number with a number of digits equalling 11 only.
Can the MaxLength Property implement this? I'll need the code if it can.
Thanks.
Obinna from Nigeria.
Obinnaaj545
|
|
|
|
|
Obinna from Nigeria,
If you set the Max length property of the text box, then you will be prevented from entering more than 11 characters. This does no validation on the data that is being entered into the form. If you are looking at the validation of the data, you should play with the KeyUp event.
Hogan
|
|
|
|
|
Nope - you're going to have to put some code in to check the length of the textbox.
if (txtMyText.Text.Trim().Length != 0)
...
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
You can use Regex to validate input
|
|
|
|
|
Simple question: Why
HKEY_CLASSES_ROOT\\[^\\]*
regex matches following strings:
HKEY_CLASSES_ROOT\.123\OpenWithProgIDs ,
HKEY_CLASSES_ROOT\.ac3\OpenWithList\CTCMSu.exe
I want to get only direct subkeys of HKEY_CLASSES_ROOT, that is:
HKEY_CLASSES_ROOT\.ac3 and HKEY_CLASSES_ROOT\.123 .
I use Regex.IsMatch instance method with IgnoreCase option.
Help!
Thanks
Greetings - Gajatko
|
|
|
|
|
Gajatko,
Rather than using a regular expression, why don't you use the method build into the framework.
//The parent key you want to look at.
RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software");
//All the first level children of the parent key in a string array.
string[] allSubKeys = rk.GetSubKeyNames();
Hogan
|
|
|
|
|
Your Pattern Seems to be right
I just use your pattern like this and get your desired results
string val
MessageBox.Show(Regex.Match(val, @"HKEY_CLASSES_ROOT\\[^\\]*").ToString());
good luck
|
|
|
|
|
"strange" is a too small word.
I use following code:
bool isMatch = Regex.IsMatch(keyPath);
where (from the Watch , Regex is a variable here):
Regex = {HKEY_CLASSES_ROOT\\[^\\]*}
keyPath = "hkey_classes_root\\.123\\openwithprogids"
isMatch = true
???
Greetings - Gajatko
|
|
|
|
|
String input = @"HKEY_CLASSES_ROOT\.123\OpenWithProgIDs
HKEY_CLASSES_ROOT\.ac3\OpenWithList\CTCMSu.exe";<br><br><br>
Regex r = new System.Text.RegularExpressions.Regex(@"HKEY_CLASSES_ROOT\\(?<subkey>[^\\]*)",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
MatchCollection coll = r.Matches(input);
foreach (Match match in coll)
{
string subKey = match.Groups["subkey"].Value;
Console.WriteLine("subkey = {0}" , subKey);
} This will return you .123 and .ac3 .
Sorry about code layout - having a nightmare with 'code' and 'per' tags
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.
|
|
|
|
|
Because it's finding an occurrence of the string you want inside of the string --
HKEY_CLASSES_ROOT\.123\OpenWithProgIDs will match HKEY_CLASSES_ROOT\.123
HKEY_CLASSES_ROOT\.ac3\OpenWithList\CTCMSu.exe will match HKEY_CLASSES_ROOT\.ac3
|
|
|
|
|
So what should I do to get only these matches which apply to a whole string, and not to its substr? Or: How can I check whether it is a substring or entire one?
Greetings - Gajatko
|
|
|
|
|
This is a solution
System.Text.RegularExpressions.Match match = Regex.Match(keyPath);<br />
<br />
return (match.Groups[0].Success && match.Groups[0].Value == keyPath);<br />
Thanks all, especially PhilDanger.
Greetings - Gajatko
|
|
|
|
|
Hi,
I've a COM object, which can only be accessed from same thread as created. Some of the COM-object operations are time consuming. If I create that COM-object on the application thread, sometimes the UI freezes (of course) while the object is working. I would like to create and use that COM-object on diffrent than application thread, but I don't know how to do that.
Of course I now how to create threads and stuff, but I don't know how to keep those threads "alive" while no COM-object work is needed. I tried to create new Thread , start it, create a new Control object and access that thread by Control.Invoke(), but that is not working, 'cause the control seems to know the main application thread and decides to run on the main thread instead of thread where it is initialized.
I also tried to use background worker, but I doubt that when worker.RunWorkerAsync() method is called, it runs always on same the thread. It does when I have a simple application, but if there were some other multi threading operation's (in the same application) i thing they would probably use the thread used by background worker(when not working) so the background worker would take other not-used thread from thread pool(if needed) and the COM-object won't work on other thread than the one on which it was created.
I hope I made myself clear enough
thanx for help
|
|
|
|