Wednesday, July 31, 2013

How to delete an element from an array in C#

LINQ: (.NET Framework 3.5)

int[] numbers = { 1, 3, 4, 9, 2 };
int numToRemove = 4;
numbers = numbers.Where(val => val != numToRemove).ToArray();
Non-LINQ: (.NET Framework 2.0)

static bool isNotFour(int n)
{
    return n != 4;
}

int[] numbers = { 1, 3, 4, 9, 2 };
numbers = Array.FindAll(numbers, isNotFour).ToArray();
If you want to remove just the first instance:

LINQ: (.NET Framework 3.5)

int[] numbers = { 1, 3, 4, 9, 2, 4 };
int numToRemove = 4;
int numIndex = Array.IndexOf(numbers, numToRemove);
numbers = numbers.Where((val, idx) => idx != numIndex).ToArray();
Non-LINQ: (.NET Framework 2.0)

int[] numbers = { 1, 3, 4, 9, 2, 4 };
int numToRemove = 4;
int numIdx = Array.IndexOf(numbers, numToRemove);
List<int> tmp = new List<int>(numbers);
tmp.RemoveAt(numIdx);
numbers = tmp.ToArray();

Disable text selection with css

1. 
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
 
 
2.
 
<div 
 style='-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;' 
 unselectable='on'
 onselectstart='return false;' 
 onmousedown='return false;'>
    Blabla
</div>
 
 
 
 

Friday, July 26, 2013

C# find exact-match in string

bool contains = Regex.IsMatch("Hello1 Hello2", @"(^|\s)Hello(\s|$)"); // yields false
bool contains = Regex.IsMatch("Hello1 Hello", @"(^|\s)Hello(\s|$)"); // yields true

Monday, July 22, 2013

Get Country Name From Ip


1) Right Click on Project Solution 
 





 
 
 
2) copy past this link in Address bar
http://ip.fecundtechno.com/GetCountryCode.svc?wsdl 
 
 














sad




 
 
Give Namspace name you want and Click OK 
 
now add Add namespace in c# file  
like using ServiceReference2

now

call service

GetCountryCodeClient client = new GetCountryCodeClient();
 
client.GetCountryName("<here give ip address>"); 
 
 
 

Opps Part 1 : Abstraction

  Abstraction in C# is a fundamental concept of object-oriented programming (OOP) that allows developers t...