LINQ TO Object Sample
LINQ:
LINQ stands for “Language Integrated Query”.
Different datastores has got different query languages. Microsoft’s idea is providing one query language syntax to all the datastors to make developer job easier.
This lead to invention of LINQ with .NET3.5
LINQ is a concept of performing queries based on language syntax.
LINQ syntax:
var res= from variablename in source
where condition
group by...
order by...
select variablename;
source can be database, object, xml document.
LINQ can be classified into 3 types:
1) LINQ to Object.
2) LINQ to SQL.
3) LINQ to XML.
LINQ to object:
Applying linq query expression to object is called “Linq to object”.
Ex:
Int[]a={2,5,6,7,1,3};
//Display number>=5
var res = from aa in a
where aa>=5
order by aa descending
select aa;
LINQ Samples: Restriction Operators
Where - Simple 1
This sample uses where to find all elements of an array less than 5.
public void Linq1()
{
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var lowNums =
from n in numbers
where n < 5
select n;
Console.WriteLine("Numbers < 5:");
foreach (var x in lowNums)
{
Console.WriteLine(x);
}
}
Result
Numbers < 5:
4
1
3
2
0
Where - Indexed
This sample demonstrates an indexed Where clause that returns digits whose name is shorter than their value.
public void Linq5()
{
string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
var shortDigits = digits.Where((digit, index) => digit.Length < index);
Console.WriteLine("Short digits:");
foreach (var d in shortDigits)
{
Console.WriteLine("The word {0} is shorter than its value.", d);
}
}
Result
Short digits:
The word five is shorter than its value.
The word six is shorter than its value.
The word seven is shorter than its value.
The word eight is shorter than its value.
The word nine is shorter than its value.
Don't Be A Computer Virus Victim
How To Avoid Computer Virus?
I think it's great that Macs enjoy "virus protections" that the PC doesn't. But if you think you're 'safe' because you're trusting the computer, consider the fact that the vast majority of PC users aren't on Macs, so hackers don't bother to write viruses for them. Knowing that, you still must understand that viruses get triggered not because the computer is a PC but because the user isn't paying attention.
Don't blame PCs, blame users. As long as users continue to allow their email programs to automatically launch files, idiocy like the Sobig virus will continue. This was the fifth version of this virus and they keep getting nastier than their predecessors.
It takes simple common sense and a lot of meticulousness to keep from launching viruses but it's not hard. Here's a list of the precautions I take to avoid computer viruses.
Don't download anything from anyone you don't know or aren't expecting... EVER. For all you VAs, and publishers and whoever else out there is trading files back and forth with your clients... Stop and make sure that your client has a safe system before you start trading files with them. It's worth the time.
2. Turn off the autolaunch in your email client. I don't even auto-launch graphics. Furthermore, READ YOUR EMAIL ONLINE! Don't download the email until you're 100% sure it is safe. Use Netscape, use Yahoo, use Eudora, use Simplecheck; I'm sure there are others.
3. If your email has an attachment, go into your headers and look at it. If it's got a pif or scr extension, chances are it's a virus. If it's any Microsoft program file, and you aren't expecting it, it in itself probably isn't a virus, but it could very easily have a virus embedded in it. The only things that hacker's haven't been able to embed viruses into, to my knowledge, are pictures. But just because it says it's a picture doesn't mean it is. Look at the attachment name. File names don't lie. If it's a .jpg.scr extension, it's a virus.
4. Antivirus protection programs are only ever as up to date as known viruses. They are also the first target of a virus, so don't trust the antivirus protection program alone. If you've used your eyes and don't believe it's a virus, scan it anyway. I use Yahoo, because they keep Norton up to date and I don't have to run it on my system. Norton in and of itself is a great antivirus protection program, but it's not infallible.
5. Set your computer so it doesn't autolaunch files, updates, security checks, html pages, cookies, etc. without your permission!
6. Get a quality anti-spyware program - They're designed to get rid of programs on your system that send your data to the web and as such could be opening holes that you don't know about.
7. Set up a software firewall. If you don't have a software firewall built in, upgrade your OS. And make sure everyone on your LAN is set up with the same firewall.
8. Don't rely only on the software; set up a hardware firewall. It's called a router and it's easy to set up and maintain.
9. Take the time and make the effort to understand how viruses and worms get onto your computer and you can virtually stop them all in their tracks.
10. Once you've got all your holes closed, get someone who knows what they're doing to test it from the Internet side. If you don't have someone, I can refer someone.
11. Don't let kids on the 'Net on your system! I find it funny that businesses will spend billions of dollars on marketing and advertising, but they leave their computer systems open to hackers whose sole purpose in life is to take advantage of KNOWN cracks in the system. In my opinion, the only real hole is the User. If you don't protect your system, nobody else will.
I probably sound a little cocky telling everyone my anti-virus procedures like this, but I'm not really. I have very sensitive data on my system I cannot afford to lose or to have sent out willy nilly to the Internet. So I'm cautious. I'm also smart enough to know that the second I let my guard down, something is going to find its way in and I won't be able to say "never" again. But I don't intend to let my guard down.
And if anyone out there is serious about doing everything you can to stop from getting a virus, but don't have the computer literacy to feel you can do it, email me and I'll find the time to help you put it all together.
No comments:
Post a Comment