Recently I came across a fine technique to mark your old code as obsolete in C#. I did some research work and Book called the same as an Insert attribute.Leaving the theory apart the practical was was that interested me the most and here I present an example of the same.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Types
{
class Program
{
enum weekdays {mon=1,tue,wed,thurs,fri,sat,sun}
//Use of obsolete attribute to mark a function a obsolete
[Obsolete("Use newmethod", true)]
static void oldmethod()
{
Console.WriteLine("No");
}
static void newmethod()
{
Console.WriteLine("Yes");
}
public static void Main(string[] args)
{
int x = (int)weekdays.wed;
Console.WriteLine("The wednesday Enum value is {0}",x);
newmethod();
}
}
}
now when I call "oldmethod()" It gives an error with a message specified as in the code...
and on calling "newmethod()" it runs fine
I peeped more into their family and found following attributes also as a part which I will discuss later
AttributeUsage
AttributeTargets
Conditional
Obsolete as discussed in this post...
Tuesday, September 27, 2011
Boxing and Unboxing in OOPS
Boxing is a process of conversion of a value to generic object type for example
Consider the following code
Int alpha=1;
object boxed_alpha= alpha;
This conversion to generic type is called as boxing
Unboxing is the reverse of a boxing continuing with the above example let us unbox boxed_alpha as a string
String string_alpha=(String) boxed_alpha;
OR
String string_alpha=boxed_alpha.ToString();
I will discuss its use subsequent comments
Consider the following code
Int alpha=1;
object boxed_alpha= alpha;
This conversion to generic type is called as boxing
Unboxing is the reverse of a boxing continuing with the above example let us unbox boxed_alpha as a string
String string_alpha=(String) boxed_alpha;
OR
String string_alpha=boxed_alpha.ToString();
I will discuss its use subsequent comments
Thursday, September 15, 2011
Getting the address of last visited page
The "document.referrer" is a string object that holds a web address of the document from which the current HTML document was reached
The Link Object of Document in javascript
In java script the link object as following properties
1) Link.hash->contains the hash portion of the web address
2) Link.host->contains host information from the links web address
3) Link.href->contains entire web address specified in the link
4) Link.hostname->contains information regarding hostname from links web address
5) Link.pathname->contains path to the file link is directed to
6) Link.port->contains the port specified in web address
7) Link.protocol->protocol specified in link's web address
8) Link.search->Querystring specified in the web address
9) Link.target->object containing name of target window
10)Link.innerHtml->Text that shows up for the link
1) Link.hash->contains the hash portion of the web address
2) Link.host->contains host information from the links web address
3) Link.href->contains entire web address specified in the link
4) Link.hostname->contains information regarding hostname from links web address
5) Link.pathname->contains path to the file link is directed to
6) Link.port->contains the port specified in web address
7) Link.protocol->protocol specified in link's web address
8) Link.search->Querystring specified in the web address
9) Link.target->object containing name of target window
10)Link.innerHtml->Text that shows up for the link
Monday, September 12, 2011
To get information regarding current browser
for(x in navigator)
document.write(x+"="+navigator[x]+"
");
document.write(x+"="+navigator[x]+"
");
Subscribe to:
Posts (Atom)