tag:blogger.com,1999:blog-10530715474690088902024-02-24T07:32:47.077+05:30Hub of Computer Tricks and ProgrammingAkashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.comBlogger75125tag:blogger.com,1999:blog-1053071547469008890.post-42438589528761924502014-05-12T14:40:00.002+05:302014-05-12T14:40:49.277+05:30Generic Function to convert string to Enum
private T GetEnumFromString<T>(string value)
{
try
{
T t;
t = (T)Enum.Parse(typeof(T), value);
return t;
}
catch (Exception E)
{
return (T)((object)0);
}
}
Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-30365597859518631782014-04-14T13:42:00.001+05:302014-04-14T13:42:13.923+05:30The Heartbleed Bug (CVE-2014-0160)
Neel Metha from Google Security discovered incorrect memory handling in Open TLS Heartbeat extension. By which attacker can access upto 64K of memory of client or server and can expose Private key and other secret data.
Affected users should upgrade to OpenSSL 1.0.1g. Users unable to immediately
upgrade can alternatively recompile OpenSSL with -DOPENSSL_NO_HEARTBEATS.
For complete Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-74861406131551446652014-04-13T13:13:00.002+05:302014-04-14T13:45:33.626+05:30Dock panel like animated buttons in WPF(XAML)
Like dockpanel buttons(Buttons which grows up as mouse enters on button) in windows, we can have the buttons in WPF without writing any C# or VB code. This can be achieved by using EventTriggers & DoubleAnimations.
As mentioned in above image as mouse enters on Recycle Bin icon, it grows up, similar thing can be achieved in wpf, sample XAML is written below.
Code:
<Grid Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-79535172573820013742014-04-11T17:38:00.002+05:302014-04-16T16:33:51.906+05:30Deferred Execution in LINQ
Deferred Execution of Query
class Sample
{
public int i;
public String str;
}
static void Main(string[] args)
{
List lst = new List();
lst.Add(new Sample() { i = 1, str = "String1" });
lst.Add(new Sample() { i = 2, str = "String2" });
lst.Add(new Sample() { i = 3, str = "String3" });
lst.Add(new Sample() { i = 4, str = "String4" });
Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com1tag:blogger.com,1999:blog-1053071547469008890.post-44736849563541638702014-04-09T14:01:00.002+05:302014-04-11T17:41:01.186+05:30Factory Design pattern
Factory design pattern provides you an interface creating a single object, but let subclass decide which class to instantiate. This pattern is used most frequently when we are having common functionality with different methods for different objects.
In that scenario, we will create an interface with defining common functionality which will be implemented by the classes. A class will be defined Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-24135469813133262912014-04-04T13:01:00.001+05:302014-04-09T14:04:11.763+05:30TargetInvocationException was unhandled "Exception has been thrown by the target of an invocation." issue in WPF
In WPF, most probably the issue occurs when we are accessing null object in the constructor of the code file of the XAML or If you are invoking "PropertyChanged" event without having null check inside the constructor.
Example 1:
public MainWindow()
{
InitializeComponent();
&Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-39184168284525958512014-04-02T15:15:00.002+05:302014-04-04T13:02:41.001+05:30"if" condition inside Select Clause of LINQ Query.
In LINQ you can't use "if" statement directly in select clause, but you can achieve this by using ternary operator.
Consider you are querying an Array of object & the object internally contains another object. We have to select some field from inner object. But it may be chance that for some cases inner object is null. So to prevent your query from throwing "Object Reference not set to Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com2tag:blogger.com,1999:blog-1053071547469008890.post-53923453204862649032013-07-23T11:02:00.000+05:302013-07-23T12:12:56.203+05:30C# Null-Coalescing Operator (??)
C# has an operator called Null-Coalescing Operator(??), this operator takes two operands. If left hand side operand is not null then it returns left hand side operand else it returns right hand side operands. It is very effective to assign default value to a variable.
This variable can be used with reference type as well as nullable value types. A sample code for the use of this operator is Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-36824001584516144452013-07-18T12:38:00.001+05:302013-07-18T12:58:25.190+05:30ERROR: Couldn't Find BOOTMGR while booting BackTrack via Bootable pendrive
I was trying to boot my machine with Backtrack via bootable pendrive, but unfortunately I got an error by saying
Couldn't Find BOOTMGR
boot:
No need to worry, It has just not found the boot loader. so we will have load that by the command. Just write the following command and it will be start loading
boot: /casper/vmlinuz boot=casper initrd=/casper/initrd.gz text splash vga=791 Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com1tag:blogger.com,1999:blog-1053071547469008890.post-43754552528562241332013-07-01T12:23:00.000+05:302013-07-01T12:23:34.359+05:30How to declare Hashtable or ArrayList in XAML.
To declare Hashtable or ArrayList in xaml, we need to include the System.Collection namespaces in XAML by using the below key
xmlns:col='clr-namespace:System.Collections;assembly=mscorlib'
After declaring the namespace we can use all the class of System.Collection namespace with col: prefix
Code to Declare the HashTable in XAML:
<col:Hashtable x:Key='hash'&Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-78912256146589197092013-05-02T22:54:00.001+05:302013-05-02T22:54:37.139+05:30Change Style of ListBoxItem when we use ItemTemplate in ListBox.
We will see how can we change background and foreground of any ListBoxItem on MouseOver or on Selection, and for ListBoxItem, ItemTemplate is being used.
Consider a ListBox in XAML, in which, ListBoxItem contains multiple Label via ItemTemplate. Now you want the background color and the text color of the Labels to be changed on Mouse Over or on Selection of the Item. To achieve this we can use Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com1tag:blogger.com,1999:blog-1053071547469008890.post-2999544029781711532013-04-24T12:34:00.001+05:302013-04-25T22:48:09.978+05:30What is Process?
Process: Any
program running in computer is a process. So there can be multiple processes
running in same computer or there can be single process running. Each and every
process will have own flow of control. In sequential execution environment, all
the process are executed in sequentially. In multiprocessor environment all the
process are switched forth and back.
Each Anonymoushttp://www.blogger.com/profile/04802850286183240801noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-8837054669315554462013-01-10T16:00:00.000+05:302013-01-10T17:27:18.300+05:30ComboBox in WPF DataGrid's Column Header
Here, In this article, we are going to discuss, how can we add framework elements in WPF Datagrid's column header. We will add combo box in the header. To add Combobox in the Header of DataGrid we use [GridColumn].Header tag. In the tag we can add any element directly.
<tools:DataGridTextColumn.Header>
<ComboBox x:Name='txtCbo75P' ItemsSource='{Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-14388496519449829532013-01-09T22:36:00.001+05:302013-01-10T17:27:09.625+05:30Create Nested headers in WPF DataGrid
In WPF many times we may require to render a data grid which contains multilevel headers, for example we have columns FirstName, LastName, Address1, Address2, City, State. Now we have to render a grid in which we have these columns these columns will have group name above the column header. It means there will be another level of header above these. In our case FirstName and LastName will Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com1tag:blogger.com,1999:blog-1053071547469008890.post-79035407921153992692012-12-22T20:17:00.000+05:302012-12-22T20:18:09.378+05:30WPF StringFormat example in Binding<!--[if gte mso 9]>
<![endif]-->
<!--[if gte mso 9]>
Normal
0
false
false
false
EN-IN
X-NONE
X-NONE
<![endif]--><!--[if gte mso 9]>
Anonymoushttp://www.blogger.com/profile/04802850286183240801noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-50430208604108153542012-12-22T15:19:00.000+05:302012-12-24T13:15:06.534+05:30Difference between BOSS and LEADER
<!--[if gte mso 9]>
<![endif]-->
<!--[if gte mso 9]>
Normal
0
false
false
false
EN-IN
X-NONE
X-NONE
<![endif]--><!--[if gte mso 9]>
Anonymoushttp://www.blogger.com/profile/04802850286183240801noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-68339489416999244132012-12-17T19:16:00.002+05:302014-05-02T14:09:49.522+05:30Custom / Partial Projection in LINQ to Hashtable / Dictionary
Like SQL we can project partial or custom data in output. In the output of LINQ Query it will be an enumerable collection of anonymous type. This anonymous type is being created by using new operator in the select clause and member fields are generated dynamically in the select new part of the LINQ.
Consider a data dictionary and structure as followed:
public static Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-7038314370299050032012-12-17T13:46:00.000+05:302012-12-17T13:47:44.442+05:30Where Clause with LINQ to Hashtable / Dictionaries
In this article, we will discuss How can we use where clause in LINQ to Object(Hastable / Dictionaries). Many time while working with the Dictionaries or Hashtables, we may require to find out the values from them which satisfies some specific criteria. In that case we used to write iterations and then find the values which satisfies the criteria. Maybe writing the loop is a easy task forAkashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com1tag:blogger.com,1999:blog-1053071547469008890.post-16058091899365267522012-12-16T15:29:00.000+05:302012-12-17T13:47:58.580+05:30LINQ: Join operations on Hashtables / Dictionaries
In this example we will discuss, how to perform Join operation on dictionaries / hash tables.
Consider 2 Dictionaries, one dictionary contains Roll No (Int) as key and a Structure (marks) (which contains marks of student) as value. Another dictionary contains Roll No(Int) as key and Name of Student (String) as value. Now we have to find name of students and corresponding marks ofAkashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-44512044481333052352012-12-15T17:15:00.001+05:302012-12-15T17:22:17.424+05:30C# Sending Information / data from Child to Parent class using events and delgatesIn the previous post C# Notify Parent From Child using events and delegates , we were just notifying the parent class about some processing happening in the child class.
But we were not sending any information or data to parent class about what processing is happening in child class. We have taken the same example taken in C# Notify Parent From Child using events and delegates and Anonymoushttp://www.blogger.com/profile/04802850286183240801noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-76651409045911386412012-12-15T16:40:00.001+05:302012-12-15T16:40:34.553+05:30Operations on specific elements of array by using LINQ
Here I am considering count operation has to be performed on array. As we know that if sum of specific elements of array is to be found, then we have to iterate the array and check whether element of the array satisfies the predicate or not. If it satisfies then increase the count else ignore it. But how is it, if I say that we need not to iterate the array to find the count or any such kind of Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-13779789748988117772012-12-15T13:04:00.000+05:302013-01-10T17:27:37.852+05:30Introduction to LINQ
Language INtegrated Query (LINQ) was introduced very 1st with the .Net framework 3.5. it bridges the gap between the world of objects and world of data.
LINQ extends the language by so called query expressions, which looks like a SQL Statement, by which we can extract and process data from array, Enumerable collection of classes, XML documents, MS SQL Tables, third party data sources etc.
List Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-4770633457841326752012-12-15T00:09:00.003+05:302013-01-10T17:27:54.389+05:30C# Notify Parent From Child using events and delegatesWhile creating an application, we often come across scenarios where we have parent child relationship between objects.
When we want to pass some information from parent to child, it is very simple as we have the reference of the child object in the parent and we pass the information using message passing technique, where we call some public method of child and achieve the desired result.
But Anonymoushttp://www.blogger.com/profile/04802850286183240801noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-46273732302641426492012-12-14T10:55:00.004+05:302012-12-14T10:56:51.379+05:30events in C#
An event allows a class or resource to notify the other classes or resource, when something required event occurs. The resource that raises the events is knows as publisher and the resource that handles the event is known as subscriber. In C# visual application we handle events like button clicked, combo box selection changed events etc. Similarly, we can raise our custom events when Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0tag:blogger.com,1999:blog-1053071547469008890.post-11884095877990995442012-12-13T11:29:00.001+05:302012-12-13T15:27:22.817+05:30delegates in C#
A delegate is a type that references a method. Once a delegate is bound to a method, it behaves like method. It can be used like other methods.
public delegate void valueEntered(string value);
Any method that matches the delegate's signature including return type, parameters etc, can be assigned to the delegate.
delegate's Overview
It is like a function pointer in C++.
It Akashhttp://www.blogger.com/profile/03343674517768400422noreply@blogger.com0