Wednesday, April 17, 2013

C# Serialization and Deserialization


As we know you make an object serializable by either implementing the ISerializable interface or by placing the [Serializable] at the top of the class.


1. Students Class


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SysDiagnosis
{
    public class Student
    {
        public string Name { get; set; }
        public string ID { get; set; }
        public int Age { get; set; }
        public string Gender { get; set; }
        public double Grade { get; set;}        
    }
}





2. SerilizeHelper Class



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace SysDiagnosis
{
    public  class SerializeHelper
    {
        public static void SerializeMe(object obj, string strPath)
        {
            XmlSerializer serilizser = new XmlSerializer(obj.GetType());
            StreamWriter writter = new StreamWriter(strPath);
            serilizser.Serialize(writter.BaseStream,obj);
        }
    }
}


3. Main Program


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace SysDiagnosis
{
    class Program
    {
        static void Main(string[] args)
        {
            Student student = new Student();
            student.Name = "Vinodh";
            student.ID = "EE01";
            student.Age = 27;
            student.Gender = "Male";
            student.Grade = 7.50;
            Console.WriteLine("Serializing object to XML");
            SerializeHelper.SerializeMe(student,@"C:\students.xml");
            Console.ReadLine();                          
        }
    }
}


4.Ouput File : (c:\students.xml)


<?xml version="1.0"?>
<Student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Name>Vinodh</Name>
  <ID>EE01</ID>
  <Age>27</Age>
  <Gender>Male</Gender>
  <Grade>7.5</Grade>
</Student>




 class Program
    {
        static void Main(string[] args)
        {
            Student student = new Student();
            student.Name = "Vinodh";
            student.ID = "EE01";
            student.Age = 27;
            student.Gender = "Male";
            student.Grade = 7.50;
            Console.WriteLine("Serializing Object to XML");
            SerializeHelper.SerializeMe(student, @"C:\students.xml");
            Console.WriteLine("Serializing XML to Object");
            SerializeHelper.SerializeMe(@"C:\students.xml", new Student());
       }
 }






namespace SysDiagnosis
{
    public  class SerializeHelper
    {
        public static void SerializeMe(object obj, string strPath)
        {
            XmlSerializer serilizser = new XmlSerializer(obj.GetType());
            StreamWriter writter = new StreamWriter(strPath);
            serilizser.Serialize(writter.BaseStream,obj);
            writter.Close();
        }

        public static void SerializeMe(string strPath, Student obj)
        {
            XmlSerializer serilizer = new XmlSerializer(obj.GetType());
            StreamReader reader = new StreamReader(strPath);
            object deserialize = serilizer.Deserialize(reader.BaseStream);
            obj = deserialize as Student;

            Console.WriteLine(obj.Name);
            Console.WriteLine(obj.ID);
            Console.WriteLine(obj.Age);
            Console.WriteLine(obj.Gender);                  
            Console.WriteLine(obj.Grade);


        }
    }
}


Serializatiion :

https://www.codeproject.com/Articles/1789/Object-Serialization-using-C
http://www.c-sharpcorner.com/uploadfile/yougerthen/how-to-serialize-an-object-using-an-iserializable-interface/


Wednesday, January 2, 2013

Semantic Web in plain english


The semantic web is about making computers behave (or ‘think’) more like humans. The easiest way to understand what this means is to use a cooking analogy. Think of each website where you put your content as a big cookpot. You might throw a carrot into one pot and tag it ‘carrot’, and into another you might put some spaghetti and tag it ‘pasta’. Computers are fine with this kind of input.
But what computers can’t do yet is understand that the thing you called ‘carrot’ is a root vegetable, is full of Vitamin A – and that you are making minestrone soup. It also doesn’t know that you have another pot simmering, and that there’s pasta in there. Or that you need to make a sauce for it. This kind of thinking requires context, and an ability to see the big picture – that is, to know what’s in each pot, and to understand that you’re making dinner. That’s all that data-meshing is; it’s about applying meaning to information from different sources. This is what the semantic web is all about; I call it the “web of meaning” or the “contextual web”. It means being able to ask your computer everything from “When did I last have Sally over?” to “Can I afford a new laptop this month?”.

Wednesday, November 21, 2012

cannot be opened because its project type (.csproj) is not supported by this version of the application.

Go to Start> All Programs > Visual Studio 2008 > Visual Studio Tools > Click Visual Studio 2008 Command Prompt. Type the below command and press enter.

devenv.exe /resetskippkgs

Monday, August 27, 2012

SQL Delete current database

I need to delete my current database which I am using it , I googled around and found this answer:

http://sqlserver2000.databases.aspfaq.com/how-do-i-drop-a-sql-server-database.html

ALTER DATABASE myDataBase
    SET SINGLE_USER
    WITH ROLLBACK IMMEDIATE

DELETE DATABASE myDataBase 

Thursday, August 16, 2012

C# difference between StringBuilder and String Object

The most common operation with string is concatenation, and this has to be performed very efficiently.
When we use String objects to concatenate two strings , then a new copy of string object is created in memory by adding two objects , and the old string object is deleted.

So we use StringBuilder to do it in a effective way, here the concatenation is done on the exsisting  string, hence the insertion is faster. Concatenation is done using Append() method