Skip to main content

Posts

C# Learning: using nullable types

Let’s say your program needs to work with a date and time value. Normally you’d use a DateTime variable. But what if that variable doesn’t always have a value? That’s where nullable types comes in really handy. All you need to do is add a question mark (?) to the end of any value type, and it becomes a nullable type that you can set to null. bool? myNulableInt = null; DateTime? myNullableDate = null; You will find out that the question mark T? is an alias for Nullable<T>.

C# Learning: strut

One of the types in .NET we haven’t talked about much is the struct. struct is short for structure, and structs look a lot like objects. They have fields and properties, just like objects. And you can even pass them into a method that takes an object type parameter: A struct looks like an object… …but isn’t an object public struct Dog { public string Name; public string Breed; public Dog(string name, string breed) { this.Name = name; this.Breed = breed; } public void Speak() { Console.WriteLine(“My name is {0} and I’m a {1}.”, Name, Breed); } } But structs aren’t objects. They can have methods and fields, but they can’t have finalizers. They also can’t inherit from other classes or structs, or have classes or structs inherit from them. Structs are best used for storing data, but the lack of inheritance and references can be a serious limitation. But the thing that sets structs apart from objects more than almost anything else is tha...

C# Learning: LINQ

C# has a really useful feature called LINQ (which stands for L anguage IN tegrated Q uery). The idea behind LINQ is that it gives you a way to take an array, list, stack, queue, or other collection and work with all the data inside it all at once in a single operation. But what’s really great about LINQ is that you can use the same syntax that works with collections as you can for working with database LINQ makes working with data in collections and databases easy. - to be updated later...

C# Learning : exception handling

In .NET, when an exception occurs, an object is created to represent the problem. It’s called, no surprise here, Exception. When your program throws an exception, .NET generates an Exception object. Exceptions are all about helping you find and fix situations where your code behaves in ways you didn’t expect. In C#, you can basically say, “Try this code, and if an exception occurs, catch it with this other bit of code.”

C# learning: about the serialization

I've been using seriazation for several years, this is the best explaination for me about this theory. Yes, It saves the complete state of the object, so that an identical instance can be brought back to life on the heap later! When an object is serialized, all of the objects it refers to get serialized, too. It is actually very cool.