|
I see
That's because productsField is null for the first time that you want to add a product
then wrtie:
<br />
....<br />
if(productField!=null) products.AddRange(productField);<br />
....<br />
or you can make it empty (instead of null):
<br />
...<br />
private Product[] productField=new Product[]{};<br />
...<br />
and there would be no need to check if productField is null in AddProduct routine.
I Prefer the second approach.
Regards
|
|
|
|
|
Holy crap it's working. Thanks so much for your help and you SPEEDY responses.
I've never worked with classes in this fasion before and I'm still trying to understand what is going on here because I want to learn. Maybe you could explain this for me? Also since I don't really understand this, is there going to be multiple array lists created and cause memory issues. It seems to me like it will create a new list every time i really just want to add an object to the same list????
so this is decaling product as an empty array of type products?
private Product[] productField=new Product[]{};
new array list?
ArrayList repReqs = new ArrayList();
confusion here: to me this seems like it's creating a range of arrays?
shouldn't it be a collection of class objects?
repReqs.AddRange(this.repairRequestsField);
confusion here: now your adding an object to your array list, but how does it
know to use the new range?
repReqs.Add(rr);
confusion here: basically no clue.
this.repairRequestsField = (RepairRequests[])repReqs.ToArray(typeof(RepairRequests));
I really want to get a better grasp on some more complex c# aspects like this. Do you have any suggestions for good books?
thanks.
-- modified at 9:54 Friday 25th August, 2006
|
|
|
|
|
Hi
Yse you can declare an empty array using this syntax:
<br />
object[] arr=new object[]{};<br />
Well an arraylist is a collection object that you can add other obejcts to it(using its Add method) and it has a lot of use,you can enumurate it using its enumurator and C# foreach keyword like this:
<br />
foreach(object obj in myArrayList)<br />
{<br />
do somthing with obj;<br />
}<br />
When you use AddRange method all the members of the passing array will be added to your arraylist it's something like:
<br />
foreach(object item in myArray)<br />
{<br />
myArrayList.Add(item);<br />
}<br />
We did this here because we wanted to save the current state of our object and then add a new item to our arraylist.
Finally we convert our arraylist into a Product array again.
First we make an array from out arraylist using its ToArray() method telling it that the type of stored items is Product (typeof(Product)) then we cast our array (that so far is an object array) to a product array using (Product[]);
So we've done two tasks at one line.We could write it like this:
<br />
object[] array=myArrayList.ToArray(typeof(myClass));<br />
myClass[] convertedArray=(myClass[])array;<br />
There are a lot of good books about C# and .Net programming but what I found really useful are MSDN and this site(Code Project) you can learn a lot of things about C# and programming here.
Wrox Programming C# is a good book.
There's another book that I like "Teach yourself object oriented programming in 21 days" It's written in java though.
Anyway I'm glad that you could solve your problem and If there's anything else just I will be glad if I can help.
Regards
|
|
|
|
|
Hello
If you use .Net 2.0 then instead of using arrays, you should use List<product> Generic colection.
If you use .Net 1.1, then use System.ArrayList instead, as you want your array to be dynamic and grows as you add to it.
I prefered List<product> as it's type specific generic collection. Yet ArrayList will do fine.
Regards
|
|
|
|
|
Session("dt").rows(i)("trans_no").ToString by vb
after conver to c#
Session("dt").rows(i)("trans_no").ToString();
not working
how it don ?
m_attiea
|
|
|
|
|
if dt is a datatable then...
DataTable dt = (datatable) session["dt"];
dt.rows[i].["trans_no"].ToString();
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
hey
i m creating a web appln in c#. recently i implemented session var in my website to enhance security.. but the problem is that after publishing this website on IIS(inetpub\wwwroot..), i opened it from my browser.. the sessions are not at all working..
even after entering correct username and pass.. i m redirected to login page again and again..
on the other hand when debugging the application, it works perfectly well.. m using visual web dev exp 2005
please help
Kunal Piyush
|
|
|
|
|
Sounds like either A) A windows Permissions error as debug is run in Admin or B) The code is not synced.
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
well.. as i said before implementing session variables..the thing was perfectly fine..
but still how do i go bout fixing the errors u said...
Kunal Piyush
|
|
|
|
|
Please don't cross post.
---
b { font-weight: normal; }
|
|
|
|
|
Sorry to post this but, here goes.
All of the coding I've ever done, and gotten paid for it, has been VB. I'm working on a project now that I decide to do in C#. It's a breath of fresh air, let me tell ya. It reminds of my days in college doing C++ and makes me realize how brain dead doing VB can make a guy!
Anyway, what's with this escape character stuff in C# strings? I'm having a heck of a time coming up with a regular expression that will match IP addresses with leading zeros, and I think my problem may be the escape character "/". I tried replacing / with // but still no matches. In fact every regex I found on the web for IP addresses failed to match.
Here is the function:
private void RangeCheck()
{
String sLine = "";
String sIPMatcher = "(\\[0-9]{1,3})\\.(\\[0-9]{1,3})\\.(\\[0-9]{1,3})\\.(\\[0-9]{1,3})";
RegexStringValidator test = new RegexStringValidator(sIPMatcher);
StreamReader sr = new StreamReader("c:/UniqueIPaddr_list.csv");
while (!sr.EndOfStream)
{
sLine = sr.ReadLine();
try
{
test.Validate(sLine);
if (IPList.CheckNumber(sLine))
{
lstBox.Items.Add(sLine);
}
}
catch
{
}
}
}
IPList is a class I borrowed from Bo's article here[^].
And here is an example of one of 10,000+ IP address in the .csv file: 00x.0xx.xxx.0x0
where x is any number 1-9 (didn't want to disclose an acutal IP).
No matter what I try, no matches occur. Is it my lack of C# skills, or just use of an incorrect regex?
-- modified at 10:25 Thursday 24th August, 2006
|
|
|
|
|
Hi,
try this.
(\d{1,3}\.){3}\d{1,3}
hope this works.
Nitin...
|
|
|
|
|
This will also match invalid IPs like 999.999.777.444
This one will match only well formed IPs:
^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$
(got that one from Regexlib.com)
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
dotnethead wrote: String sIPMatcher = "(\\[0-9]{1,3})\\.(\\[0-9]{1,3})\\.(\\[0-9]{1,3})\\.(\\[0-9]{1,3})";
You can use
String sIPMatcher = @"(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})";
@ character considers all characters to be text inside " "
Try it !
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
Anant Y. Kulkarni wrote: @ character considers all characters to be text inside " "
Golden, just what I was looking for!
Unfortunately Anant, your regex did not match. I think it must be the leading zeros?
The only regex that matched anything was:
String sIPMatcher = @"(\d{1,3}\.){3}\d{1,3}";
Although it will match 999.999.999.999, I know for sure that all of the IP's containing all numbers are good ones. There are however, ones with letters in them, which is why I need this regex.
Thanks for all the help....it was nice to come back to all the responses after a long meeting!
|
|
|
|
|
Hi,
dotnethead wrote: Unfortunately Anant, your regex did not match.
Actually i didnt changed the regex. I only suggested a part of solution for your escape character problem. Sorry, that i was not clear what i have posted.
-- modified at 1:55 Friday 25th August, 2006
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
Hi,
this is the modified version of my previous regex which i posted.
Regex rx =new Regex(@"^(\d{1,3}?\.){3}\d{1,3}$");
this will check the proper format for ip.
but this will also match no.s greater than 255.
so what you can do is first apply above regex expression for valid format and if found correct you can split the ip and check for each part no. is not greater than 255.
hope this works.
Nitin...
|
|
|
|
|
Thanks I'll give it a shot.
|
|
|
|
|
hi all...
i am trying to delete all the data in printer spooler
here is my code
ProcessStartInfo pns=new ProcessStartInfo("net","stop spooler");
System.Diagnostics.Process.Start(pns);
string syspath=Environment.GetFolderPath(Environment.SpecialFolder.System);
DirectoryInfo drdd= new System.IO.DirectoryInfo(syspath+"\\spool\\PRINTERS");
foreach(System.IO.FileInfo fin in drdd.GetFiles())
{
fin.Delete();
}
pns=new ProcessStartInfo("net","start spooler");
System.Diagnostics.Process.Start(pns);
everything works fine .. but the problem is if we want to print again , then we have to manually go and refresh that printer folder(where the printers are listed ) how can i automate that ..
thanx
Akhil
|
|
|
|
|
If you open your control panel (under XP) ==>
open "Sounds and Audio Devices" ==>
choose the "Audio" tab ==>
"Sound Recording" group-box ==>
Click "Volume..." button
then a window appears allowing you to choose your recording input path.
How can I program it using C# or any other language (4 eg to control selecting mic or line-in input signal)?
Greatly appreciated, this is really a challenging question..
-- modified at 10:08 Thursday 24th August, 2006
لا إله إلا الله
|
|
|
|
|
Hello
For this you must use DirectX. Here is an articles about capturing audio, and choosing which line to capture from.
DirectX.Capture[^]
For more Try the Media section[^] in CP.
I hope this helps.
Regards
|
|
|
|
|
Many thanks for your help , BUT the directX gives you the opportunity to choose among different audio devices, what I need is to be able -after choosing a certain audio device- to enable/disable the line-in or mic within the choosed audio device.
لا إله إلا الله
|
|
|
|
|
Hello
Enabling or disabling audio lines using C# would be problematic, I think. You may not do it entirely using C#. You'll have to make some Win32 API calls.
An article that would do exactly what you are looking for is Here[^]. Take a look at example 4 specially. Unfortunetaly the article is written in C++
I hope this would help, for more articles about audio and video, you may look Here[^]. Again most of them is written in C++.
Regards
|
|
|
|
|
Thanks my bro Nader, I will delve inshallah now into the Win32 APIs .
Thanks for your help
لا إله إلا الله
|
|
|
|
|
Hi,
I have developed a windows application, which open a TCP connection to some machine on some port. Then i can send any commands to the server. I get responses from the server. For example i am opening connection with Mail server and issue POP commands then i can get the list of mail messages, retrieve mail messages from server. Until now there is no problem. But i want to know how can we open a secured connection to server in the above scenario ?
Any help would be appreciable !
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|