|
hi Calla
Thanks for your response
Actually I am talking about custom Liked List(data structure).
where nodes are connected via reference to each other
We are having reference of only first node.
Thanks
|
|
|
|
|
You can use linq only on those objects which can be treated as a collection of objects.
You can read your link list at a time and store it in a list or array
and then you can apply linq query to them.
|
|
|
|
|
|
is Global variable good or bad in c#.net? If i declare Global variables instant of singleton variables its good or bad for application??
Thanks
Raj
|
|
|
|
|
As a general practice, global variables are bad. This compromises the security of the application, as well as eliminating any chance of data-hiding through the use of objects and variable passing.
Now, this of course depends on the type of information and the use of the program. You may want to use a static global variable for things like links or connection information etc. This means that the variable cannot be changed at any point of from anywhere else in the program though. It will exist as a static reference value.
What are you trying to accomplish with the global variable?
|
|
|
|
|
Eric (eD) wrote: As a general practice, global variables are bad.
Myth. Global variables should generally be avoided when possible (and used as a last resort), but they're not "bad", and there are times when you simply must use one to accomplish some tasks. Besides that, global variables *technically* aren't even possible in .Net.
Eric (eD) wrote: You may want to use a static global variable for things like links or connection information etc. This means that the variable cannot be changed at any point of from anywhere else in the program though.
Not quite. Static members in an object exist for the lifetime of the application, and can be changed from anywhere (and by any other object) if they have the appropriate visibility. In fact, it's common practice to create a static class for just that purpose. In many ways, using static class members can be fraught with as much - if not more than - "global" variables, but like globals, they're pretty damn handy in a pinch, and you shouldn't hesitate to use them if the architecture demands it.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I'd say it is pretty meaningless to say this or that programming practice is inherently good or bad. The only proper answer is always "it depends".
That said, I'm not really sure what you mean by "global variable". C# does not have them. You seem to mean instance members of a singleton. From the language's point of view that's just like any other instance member, the singleton after all is a pattern you can implement with C#, but not a concept that the C# language itself "is aware" of.
In general, if you are using the object-oriented paradigm, it is considered bad practice not to encapsulate state. Therefore, you should expose the state through properties (or methods in a few cases). These may be read-only or read-write, as long as you perform validation to guarantee object state remains valid at all times.
What is your motivation for wanting to use a "global variable"? There may be many ways to accomplish what you seek, such as using static members (which is the closest thing to global variables you can find in C#), thread data, application state (in an asp.net context) or other mechanisms.
|
|
|
|
|
Hi,
I am using VS 2008. My Datagridview is having bounded columns. Datasource is using as DataSet with Binding source.
I wanted to show these as vertical view ( swaping columns to rows)
how can i do? please help me
Ramana
|
|
|
|
|
|
Hi. I want to download a file from one website. It is really simple do it like this:
WebClient wc = new WebClient();
wc.DownloadFile(@"http://aaa.uuu", @"D:\111.gig");
But when a file is attachment... in response we have header: "Content-Disposition: attachment; filename="file.gif"", I couldn`n download file.
I`v seached smth around this problem and sow like this:
string filepath = Server.MapPath("test.doc");
FileInfo file = new FileInfo(filepath);
if (file.Exists)
{
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = ReturnExtension(file.Extension.ToLower());
Response.TransmitFile(file.FullName);
Response.End();
}
The first problem is what i couldn`t use class Response, becouse i couldn`t use System.Web.UI.
Plz, explain me, I couldn`t use System.Web.UI becouse I programming in C# but not in ASP.NET?
And could anybody help me with downloading file, which is attachment?
|
|
|
|
|
hello_amigo wrote: I programming in C# but not in ASP.NET
ASP.NET is a technology, a framework; you can't "program" in it. ASP.NET uses C#, or other lesser languages (VB.NET )
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I am trying to implement multiple dropdown lists with Access Database.
It is like this- I have a dropdown list which takes data of all users from one column in the database and shows them in the dropdown list. Then based on which user is selected, the dropdown list needs to dynamically change its contents to show the tasks related to that user and from this selection of tasks, another dropdown list needs to dynamically change itself to show the actions for that user, and that particular task.
I have not done much coding here since I have added an access datasource and generated the contents from the database into the 1st list but i am not able to take the output from that list and give it as an input to the second list and so on. I have to do it in C# and this is a web application and I am not able to figure it out.
Any help is appreciated.
SJ.
|
|
|
|
|
Don't cross post Pick one forum and use it.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
buddy, the reason i posted in both the forums is that, my topic is related to both .NET and C#. did i post it in C++, php or anything else?????? i did that only because it is related stuff and not for spamming !!!
|
|
|
|
|
|
just so you know, by saying buddy, i was following the 8th point in the link you provided !!!!!!!!
peace buddy
|
|
|
|
|
I have been programming professionally for about 3 years. I know VB.NET well. I am wanting to branch out and learn C#. Do any of you have suggestions for Open Source projects written in C#? I would like to work on something where I don't have to be very committed because it will just be in my spare time. I would also like to work on small pieces of a project at least until I get used to the syntax. Any help is appreciated.
Humble Programmer
|
|
|
|
|
If you want to learn C#, I recommend you a book named "A Programmer's Introduction to C# , 2nd Edition". And online forums are good learning tools, but to have a solid foundation, I suggest that you buy a good book and learn step by step.
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:49am.
|
|
|
|
|
Thank you for the suggestion on the book but the reason I ask about an open source project is because unless I have a reason to produce something such as helping a cause I will not write code after coding all day.
Humble Programmer
|
|
|
|
|
I have a NetForce USB modem (v.92 data transfer tech) which I want to send commands to. The problem is that I don't know what to send to the SerialPort (with WriteLine method) to receive answer from my modem. I tried "AT+DS44?" as the argument of WriteLine method and expected to receive all valid values of my modem as I read in this page : http://www.modemsite.com/56K/v92c.asp but in my DataReceive event handler when I call ReadLine function, I see that the return value is just what I wrote on the buffer; Meaning either the modem hasn't read the data(but why the event handler is risen?) or my modem is merely echoes what I write to it! I think I don't know sth about sending AT commands to modems but I don't know what?! Here's my whole c# code:
class Program
{
static SerialPort sp = new SerialPort("COM8", 56000, Parity.None, 8);
static void Main(string[] args)
{
if(!sp.IsOpen)
sp.Open();
sp.WriteLine("AT+DS44=?");
sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
ThreadStart ts = new ThreadStart(f);
Thread t = new Thread(ts);
t.Start();
}
static void f()
{
while (true) ;
}
static void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Console.WriteLine("DataRecieved..............................");
string str = sp.ReadLine();
Console.WriteLine(str + "......................................");
}
}
|
|
|
|
|
Hi,
I have several comments:
1.
having a thread execute an empty loop is the perfect way to waste a CPU core. Are you sure you want this? I wouldn't.
2.
you may want to clear both inbound and outbound buffers when using a serial port. if anything is still in there, your PC app or your peripheral could receive it once the conditions are right.
3.
The DataReceived event is raised when some data is available (some as in "an undefined quantity"). Only reading a single line of text may not return all that is available. You might just have looked over the data you are expecting!
4.
modems (or whatever is at the far end) may echo all incoming characters; that is what you would hope for when using a terminal+modem to connect to a distant computer e.g.
5.
if relying on messages (e.g. strings terminated by \r\n) you might want to explicitly program the terminator; Environment.NewLine (I assume that is the default for SerialPort.NewLine) may vary when your app travels the world and/or goes to non-Windows platforms.
6.
The hardest one of all: serial communication can be very hard; there isn't much that forces message characters (such as text ending on \r\n) to stay together; you might get a DataReceived event halfway, etc.
I tend to do one of these two:
- insert a small delay between event and Read operation
- or provide my own buffering, then extract messages when they are completely available within my buffer.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Luc has valid points; listen to him.
I don't bother with events and handlers when listening to such things (serial ports, network sockets, etc.).
I have a thread running a loop that reads any available data (if any) and then cycles. Processing the data is then handled by another part of the system (this may be what Luc referred to as implementing your own buffering).
And I don't care about newlines; I definitely would not use ReadLine on a socket or serial device.
|
|
|
|
|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
I have a simple method that takes a string as input and returns the time (in seconds) it takes to generate a another string that is the same – using System.Random.
private double timeOccurance2(string target)
{
string trial = string.Empty;
double intialTime = DateTime.Now.ToOADate();
Random rand = new Random();
while (trial != target)
{
StringBuilder b = new StringBuilder();
char[] ch = new char[target.Length];
for (int i = 0; i < target.Length; i++)
{
ch[i] = Convert.ToChar(Convert.ToInt32(Math.Floor(10 * rand.NextDouble() + 48)));
}
for (int i = 0; i < target.Length; i++)
{
b.Append(ch[i].ToString());
}
trial = b.ToString();
}
double finalTime = DateTime.Now.ToOADate();
return 24 * 60 * 60 * (finalTime - intialTime);
}
If I set target = “123246” and run the method repeatedly by clicking a button over and over, I get a random distribution of times, as expected.
Next, using the same target, I run multiple iterations of the method via BackGroundWorkers:
private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 40; i++)
{
BackgroundWorker Computation = new BackgroundWorker();
Computation.DoWork += new DoWorkEventHandler(Computation_DoWork);
Computation.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Computation_RunWorkerCompleted);
Computation.RunWorkerAsync();
private void Computation_DoWork(object sender, DoWorkEventArgs e)
{
e.Result = timeOccurance2("123456").ToString();
}
private void Computation_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
richTextBox1.Text += (string)(e.Result);
richTextBox1.Text += (char)(10);
}
The result nearly always has a group of 4 numbers within the results that have nearly identical values. for example 407, 407, 422, 438. (Humm, my computer has 4 logical processors.) The cluster does not always appear at the beginning of the result set.
Why?
modified on Tuesday, February 2, 2010 9:38 AM
|
|
|
|
|
Probably because you are creating a new instance of Random, which takes the time as seed every time
|
|
|
|