New StackExchange site proposal for Software students
Hi all,
I would like to announce a proposal for new Area5 QA site for software students.
I feel there is lot been done for the skill-set improvement for developers from uncountable sites, forums and specially stackoverflow.com.
IMHO, we need to provide a platform / Q&A site for those interested in software development, perusing or have completed relevant education. What ever software development field they are interested in, this site would help them set their path and provide advice and answer to any of their queries.
If you feel this makes sense, would highly appriciate your support
We need
-
60 followers
5 on-topic questions
5 off-topic questions
Thank you for your time and see you at software students
regards
Asad Ali Butt
Difference between Page.IsPostBack and Page.IsCallBack
Page.IsCallBack
It is getting a value indicating whether the page request is the result of a call back. Its a special postback, so a round-trip always occurs; however, unlike the classic postback, the script callback doesn’t redraw the whole page. ViewState is not updated during a callback, it is for postback. IsPostBack is true when a method in the code behind posts a page
Checks whether the Page is accessing the server for the first time or not. Unlike the IsCallBack, the ViewState is updated. IsPostBack is true when an AJax call, calls back a the page.
How to make a callback?
In the client side JavaScript code, if GetCallbackEventReference() method is reference, then when the JavaScript code is executed, a channel to the server is opened and an HTTP request is sent to the remote ASP.NET page.[1]
references: [1] Script Callback
Linq To XML: Generate Types with Nested Types using C#
In this article, we will have look at how can we generate Types with subtypes using Linq To XML
Suppose we have an XML file which holds information about Cars as their Model Name, Transmission details, Engine Details and some other information, like follows
<?xml version="1.0" encoding="utf-8" ?>
<Cars>
<Car Name = "Golf">
<Transmission Type="Manual" Gears="5" />
<Engine Type="diesel" Power="2000" />
</Car>
<Car Name = "Mazda">
<Transmission Type="Automatic" Gears="4" />
<Engine Type="Patrol" Power="2000" />
</Car>
</Cars>
Now we have class named Car as Follows
class Car
{
// struct Transmission
public Transmission Transmission { get; set; }
// struct Engine
public Engine Engine { get; set; }
}
Class car has two properties which are structs, Transmission and Engine
struct Engine
{
// Type of Engine
public string Type
{ get; set; }
// Power of Engine
public int Power
{ get; set; }
}
struct Transmission
{
// Type of Transmission
public string Type
{ get; set; }
// Type of Transmission
public int Gears
{ get; set; }
public override string ToString()
{ return Type + " " + Gears; }
}
This is how we can parse the above XML document using XElement and Linq To XML and generate the required classes
// Load Document using XElement
XElement elements = XElement.Load("XMLFile.xml");
// using Linq To Xml parse and load Objects
List<Car> CarsList =
(from e in elements.Descendants("Car")
// get new Car object
select new Car
{
// get Name for the Car
Name = e.Attribute("Name").Value,
// get Transmission details for the Car
Transmission = new Transmission()
{
Type = e.Element("Transmission").Attribute("Type").Value,
Gears = Convert.ToInt32(e.Element("Transmission").Attribute("Gears").Value)
},
// get Engine details for the Car
Engine = new Engine()
{
Type = e.Element("Engine").Attribute("Type").Value,
Power = Convert.ToInt32(e.Element("Engine").Attribute("Power").Value)
}
}).ToList<Car>();
To work over the returned List of cars we can use many methods, one of which is foreach
foreach (Car car in CarsList)
{
Console.WriteLine(car.Name);
Console.WriteLine(car.Engine.Type);
Console.WriteLine(car.Transmission.ToString());
Console.WriteLine("--------------");
}
Difference Between Debug and Release
Debug:
Release
Managing Configuration Details:
To manage the configuration details for our project we can provide custom configuration by: right click Solution -> configurationManager, or use existing settings by Project –> Propeties / Build.
Why use interfaces
This a general overview about what are the advantages for using interfaces in C#. Here are some the many reason fro which we should consider using an interface while development.
C# does not allow multiple class inheritance. We can derive from only one class at a time, but not more. We can indeed inherit our class, interface from multiple interfaces.
public class ClassB : ClassA, InterFaceA, InterFaceB
{
//
}
Consider this example:
You have a class that is capable of playing media files(mp3). You give that class to you friend who tries to play MPEG type of files. It would not be possible for him to do so without making significant changes to you class.
public class MusicPlayer
{
void Play(Mp3 _mp3File){}
}
Now consider this
Instead of passing type of mp3 file to Play Method what if you pass this Method, a derived from an interface of Type MediaType.
public interface MediaType
{ }
public class Mp3 : MediaType
{ }
public class MPEG : MediaType
{ }
public class MusicPlayer
{
void Play(MediaType _mediaFile){}
}
In this scenario, you can derive another MediaFile type and from MediaType like MPEG and pass that to the Play Method and it will happily accept it and play it for you (provided logic).
public class TestPlayers
{
public void PlayMedia()
{
MusicPlayer musicPlayer = new MusicPlayer();
musicPlayer.Play(new Mp3());
musicPlayer.Play(new MPEG());
}
}
for reference and more information:
