affiliate_link

Friday, April 17, 2009

Stop Youtube from displaying related videos once playback of the initial video starts

To stop displaying related videos we can add a parameter (rel=0 for stop displaying) to the url of the embedded code provided by you tube. See example below

http://www.youtube.com/v/u1zgFlCw8Aw&fs=1&rel=0

For complete list of parameters check the following Google API site:

http://code.google.com/apis/youtube/player_parameters.html

Thursday, April 16, 2009

Finding duplicates with SQL?

Suppose Col1 is the field name for which you want to find duplicates:

Select Col1, Count(Col1) as count
from table1
group by Col1
having Count(Col1) > 1

.

Formatting DateTime to Date in SQL

Select convert(varchar(10),GetDate(),101)

Output: 04/16/2009

Select convert(varchar(10),GetDate(),103)

Output: 16/04/2009

Rounding a number to 2 decimal places in SQL

Use T-SQL Convert Function.

Select convert ( decimal(8,2) , 9.4125 )

Output: 9.41

What is Windows Presentation Foundation (WPF)?

Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows client applications with visually stunning user experiences. With WPF, you can create a wide range of both standalone and browser-hosted applications. Some examples are Yahoo! Messenger and the New York Times Reader.

The core of WPF is a resolution-independent and vector-based rendering engine that is built to take advantage of modern graphics hardware. WPF extends the core with a comprehensive set of application-development features that include Extensible Application Markup Language (XAML), controls, data binding, layout, 2-D and 3-D graphics, animation, styles, templates, documents, media, text, and typography. WPF is included in the Microsoft .NET Framework, so you can build applications that incorporate other elements of the .NET Framework class library.

Reference: http://msdn.microsoft.com/en-us/library/aa970268.aspx

Wednesday, April 15, 2009

What is LINQ?

Strings act like value types in .Net?

System.String is a reference type in .NET. Don’t let anyone mislead you into thinking otherwise. You’ll hear people saying strings “act like value types”, but this doesn’t mean the runtime makes a copy of the string during assignment operations, and it doesn’t make a copy of a string when passing the string as a parameter.

The equality operator and String.Equals method compare the values of two string objects, and you won’t find a property or method on System.String with the ability to modify the contents of a string – only return a new string object. Because of these two behaviors we sometimes say strings have value type semantics (they feel like value types), but strings are reference types in the runtime. An assignment operation does not copy a string, but assigns a reference. The value given to a string parameter in a method call is the reference, not a copy of the string’s value.

using System;

class Class1

{

[STAThread]

static void Main(string[] args)

{

string s1 = "Hello";

string s2 = s1;

// this test will compare the values of the strings

// result will be TRUE since both s1 and s2

// refer to a string with the value "Hello"

bool result = String.Equals(s1, s2);

Console.WriteLine("String.Equals(s1, s2) = {0}", result);

// next we will check identity

// ReferenceEquals will return true if both parameters

// point to the same object

// result will be TRUE -both s1 and s2reference

// the same object.

// strings are reference types

// there is no copy made on assignment (s2 = s1)

result = Object.ReferenceEquals(s1, s2);

Console.WriteLine("Object.ReferenceEquals(s1, s2) = {0}", result);

// now we will make a copy of the string

s2 = String.Copy(s1);

// compare string values again

// result will be TRUE - both s1 and s2

// refer tostrings with the value of "Hello"

result = String.Equals(s1, s2);

Console.WriteLine("String.Equals(s1, s2) = {0}", result);

// check identity again

// result will be FALSE

// s1 and s2 point to different object instancesbecause we forced a copy

result = Object.ReferenceEquals(s1, s2);

Console.WriteLine("Object.ReferenceEquals(s1, s2) = {0}", result);

}

}

Reference: http://odetocode.com/Blogs/scott/archive/2005/07/21/1961.aspx

String Reference or Value type in .Net?

string is reference type but really special one. When you do operation of both string values like in your example
C = A, there is nothing in this operation simular to normal class behavior. So C doesn't have a reference of A. In that operation, a new string class is created and the value from string A is copied to string C. String C and String A are pointing in completly different memory address. That is way, when you have many string operation, for example loop and in every iteration you have a string manipulation, because of new string class generation, that operation is performance leak. In that situation it is preffered to use StringBuilder. Why, because StringBuilder doesn't create new string for any string operation.

Now for question, why string is not value type and it's reference type.
When you have let's say int value, Int type has defined lenght and that is 4 byte. And for every value type you know the exact memory space that will take. But for string you don't know that. It will be stupid to have a string type in wich you should always define how long it is. And if you want to put in that string variable a value with bigger lenght that string is defined, that will be disallowed.
Why is string a special class. It is special because you have a reference class, but the way of using it, looks like a value type. So, that's why you do operation like:
string C = A, and not string C = new string(A);
You don't have to instance string class because .NET framework do that for you when you first time set it's value. If you not set it's value string has value of null like any other reference type. Every language platform has a special treatment for string type. .NET is not exclusion from that too.

Reference: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6344698c-c92e-4562-966f-eae92195961d

Tuesday, April 14, 2009

What is Silverlight ?

Silverlight is a new cross-browser, cross-platform implementation of the .NET Framework for building and delivering the next generation of media experiences and Rich Interactive Applications(RIA) for the web. It runs in all popular browsers, including Microsoft Internet Explorer, Mozilla Firefox, Apple Safari, Opera. The plugin required to run Silverlight is very small in size hence gets installed very quickly.
It is combination of different technolgoies into a single development platform that allows you to select tools and the programming language you want to use. Silverlight integrates seamlessly with your existing Javascript and ASP.NET AJAX code to complement functionality which you have already created.
Silverlight aims to compete with Adobe Flash and the presentation components of Ajax. It also competes with Sun Microsystems’ JavaFX, which was launched a few days after Silverlight.
Currently there are 2 major versions of Silverlight:
Silverlight 1.0 and Silverlight 2.0( previously referred to as version 1.1).

Strongly typed vs weakly typed ?

Describe SVN ?

What is static class?

Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class. Static class members can be used to separate data and behavior that is independent of any object identity: the data and functions do not change regardless of what happens to the object. Static classes can be used when there is no data or behavior in the class that depends on object identity.

A class can be declared static (in c#) , indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.

Use a static class to contain methods that are not associated with a particular object. For example, it is a common requirement to create a set of methods that do not act on instance data and are not associated to a specific object in your code. You could use a static class to hold those methods.

The main features of a static class are:

Creating a static class is therefore much the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated.

The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.

Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.

Reference: http://msdn.microsoft.com/en-us/library/79b3xss3(VS.80).aspx

What is partial class?

One of the language enhancements in .NET 2.0—available in both VB.NET 2005 and C# 2.0—is support for partial classes. In a nutshell, partial classes mean that your class definition can be split into multiple physical files. Logically, partial classes do not make any difference to the compiler. During compile time, it simply groups all the various partial classes and treats them as a single entity.

One of the greatest benefits of partial classes is that it allows a clean separation of business logic and the user interface (in particular the code that is generated by the visual designer). Using partial classes, the UI code can be hidden from the developer, who usually has no need to access it anyway. Partial classes will also make debugging easier, as the code is partitioned into separate files.

referenced: http://www.devx.com/dotnet/Article/22603