Upload
vilciu-constantin
View
218
Download
0
Embed Size (px)
Citation preview
8/10/2019 C Sharp _ w3mentor - Part 3
1/10
w3mentor
Learning web technologies simplified!
Home
Search
8085/8086
Microprocessor Basics
C Sharp
.NET Silverlight
ASP.NET Ajax
C# ADO.NET
Access
ADO.NET Examples
C# Application Domains & Services
C# ASP.NET
C# ASP.NET LINQ
Cast
ConcatDistinct
GroupBy
Intersect
Join
OfType
OrderBy
Select
Skip/Take
Union
Where
C# ASP.NET Mail
C# ASP.NET MVC
Actions
Controller
FiltersHTML Helpers
Views
C# ASP.NET Reflection
C# Collections and Generics
C# Collections Examples
C# File Handling
C# Flow Control
C# Interoperability
C# Network Programming
C# Streams
C# Streams Examples
C# Threading
C# XML
Cryptography
Language BasicsObject Oriented Concepts C#
Csharp OOPS Examples
Windows phone 7
Input
Accelerometer
FM Radio
WPF .Net
Controls
C/C++
Arrays
Control Structures
Data Structures
File access & processing
Functions & Recursion
Interview Questions
Tuneup Utilities Avg PC Tuneup Product Key Serial
CodeSmith Code Generatorcodesmithtools.com
Template-driven. Easy to use. Your code. Your w ay. Faster!
8/10/2019 C Sharp _ w3mentor - Part 3
2/10
Pointers
User-Defined Data Types
CSS
CSS Basics
Flash
Actionscript Basics
HTML
HTML 5
HTML Basics
XHTML
Java Tutorials
Android Development
Android Http ServicesCollections
Ext GWT (GXT)
Java Data Types
Java Language basics
Network Programming
Numbers & Dates
Javascript
ActiveX
Ajax
Extjs
Images and animations
Javascript & CSS
Javascript & DOM
Javascript Events
JqueryLanguage basics
Object oriented Javascript
MYSQL
MYSQL Administration
MYSQL Basics
MySql Errors
MYSQL Functions
MYSQL Interview Questions
MYSQL Views
Perl
CGI
Modules
Perl Databases
Perl Email
Perl File Handling
Perl Functions
Perl Language Basics
Perl Networking
Perl string manipulation
Perl Web Services
Perl XML
PHP/MySQL Tutorials
CakePHP
Codeigniter
Language Basics
For statement
Functions
IF/ELSE Statement
Php Basics Examples
Switch statement
While statement
MongoDB
Object Oriented PHP
Classes/Objects
Constructor
Php OOPS Examples
PHP Arrays
Php Arrays Examples
PHP Cookies
PHP Date and Time
PHP Date Time Examples
PHP Design patterns
PHP File Handling
File read
PHP Flow Control
8/10/2019 C Sharp _ w3mentor - Part 3
3/10
PHP Forms
Php Forms Examples
PHP Graphics
PHP Mail
PHP MYSQL
Php Mysql Examples
PHP Regular Expressions
PHP sessions
PHP Web Services
PHP XML
PHP XML Examples
Wordpress
Zend FrameworkPL/SQL
PL/SQL Language Basics
PLSQL Basics Examples
PL/SQL String Manipulation
PL/SQL XML
PL/SQL Conversion
PLSQL Date Manipulation
Project Management
Cost Management
Procurement Management
Quality Management
Risk Management
Supply Chain Management
Python
Language BasicsMongoDB
Scientific computation
SAP
Introduction
Social Apps
Open Social
Social API References
Sql Server
MSSQL Basics
Transact-SQL
Video Tutorials
ASP.NET Videos
PHP Videos
Basics
Drupal Videos
Project Management Videos
Risk Management Videos
w3mentor> C Sharp
C Sharp
asp-dot-net-c-sharp
Check if a file is read only in C#
boolisReadOnly =((File.GetAttributes(filePath)&FileAttributes.ReadOnly)==FileAttributes.ReadOnly);
Display the call stack method names in C#
usingSystem.Diagnostics;
[STAThread]
publicstaticvoidMain()
{
//obtain call stack
StackTrace stackTrace =newStackTrace();
// obtain method calls (frames)
StackFrame[]stackFrames =stackTrace.GetFrames();
// display method names
8/10/2019 C Sharp _ w3mentor - Part 3
4/10
foreach(StackFrame stackFrame instackFrames)
{
Console.WriteLine(stackFrame.GetMethod().Name); // output method name
}
}
Get Name of the calling method using Reflection in C#
usingSystem.Diagnostics;
// get call stack
StackTrace stackTrace =newStackTrace();
// get calling method name
Console.WriteLine(stackTrace.GetFrame(1).GetMethod().Name);
C# Enqueue and Dequeue queue operations
QueuemyQueue =newQueue();
voidAddQueueItem(stringrequest)
{
myQueue.Enqueue(request);
}
stringGetNextQueueItem()
{
returnmyQueue.Dequeue();
}
Stack push and pop in C#StackmyStack =newStack();
voidaddRecord(stringmove)
{
myStack.Push(move);
}
stringGetLastRecord()
{
returnmyStack.Pop();
}
Arraylist properties and methods in C#
ArrayList alphaList =newArrayList();
alphaList.Add("A");
alphaList.Add("D");
alphaList.Add("W");
Console.WriteLine("Original Capacity");
Console.WriteLine(alphaList.Capacity);
Console.WriteLine("Original Values");
foreach(objectalpha inalphaList)
{
Console.WriteLine(alpha);
}
alphaList.Insert(alphaList.IndexOf("D"), "C");
alphaList.Insert(alphaList.IndexOf("W"), "J");
Console.WriteLine("New Capacity");
Console.WriteLine(alphaList.Capacity);
Console.WriteLine("New Values");
foreach(objectalpha inalphaList)
{
Console.WriteLine(alpha);
}
Declare and fill a two-dimensional array in C#
int[, ]my2DArray ={{1, 1}, {3, 5}, {5, 7}};
for(inti =0;i
8/10/2019 C Sharp _ w3mentor - Part 3
5/10
Console.WriteLine("Upper Bound");
Console.WriteLine(intArray.GetUpperBound(0));
Console.WriteLine("Array elements");
foreach(intitem inintArray)
{
Console.WriteLine(item);
}
Array.Reverse(intArray);
Console.WriteLine("Array reversed");
foreach(intitem inintArray)
{
Console.WriteLine(item);
}
Array.Clear(intArray, 2, 2);
Console.WriteLine("Elements 2 and 3 cleared");
foreach(intitem inintArray){
Console.WriteLine(item);
}
intArray[4]=9;
Console.WriteLine("Element 4 reset");
foreach(intitem inintArray)
{
Console.WriteLine(item);
}
Console.ReadLine();
Positioning elements on a Silverlight Canvas
The Canvas.Top and Canvas.Left attributes can be set within the children controls XAML to position within the Canvas relatively.
Set padding in silverlight code behind
Xaml:
Code behind:
namespace TestSilverlightApplication
{
publicpartialclassMainPage :UserControl
{
Button mybutton =null;
publicMainPage()
{
InitializeComponent();
}
privatevoidWindow_Loaded(objectsender, RoutedEventArgs e)
{
mybutton =newButton {Content ="Hi and Welcome", Width =150, Height =25};
mybutton.Padding=newThickness(10, 12, 10, 12);//set the padding using thickness
Canvas.SetLeft(mybutton, 100);
Canvas.SetTop(mybutton, 124);
canvas1.Children.Add(mybutton);
8/10/2019 C Sharp _ w3mentor - Part 3
6/10
}
}
}
Change canvas background in Silverlight .Net
Strip out all html tags in string using C#
The tags need not be correctly nested for the below implementation to work..
publicstaticstringRemoveHtmlTags(stringpInput)
{
char[]array =newchar[pInput.Length];
intarrayIndex =0;
boolinside =false;
for(inti =0;i
8/10/2019 C Sharp _ w3mentor - Part 3
7/10
response =exc.ResponseasHttpWebResponse;
}
// Check if response returns 404
if(response.StatusCode==HttpStatusCode.NotFound)
{
Console.WriteLine(urlfile1 +"Not Found");
}
else
{
if(response.StatusCode==HttpStatusCode.Ok)
{
Console.WriteLine(urlfile1 +"Found");
}
}
}
Ping a host machine to check uptime in C#
usingSystem;
usingSystem.Collections.Generic ;
usingSystem.Linq;
usingSystem.Text;
namespaceProgramSendPingtoHost
{
classProgramSendPingtoHost
{
staticvoidMain(string[]args)
{
try
{
stringhostAddress ="127.0.0.1"; System.Net.NetworkInformation .Pingping =newSystem.Net.NetworkInformation.Ping();
System.Net.NetworkInformation .PingReplyreply =ping.Send(hostAddress);
Console.WriteLine("The Host Address: {0}", reply.Address);
Console.WriteLine("Status of the ping: {0}", reply.Status);
Console.Read();
}
catch(Exception ex)
{
}
}
}
}
Output:
Convert Enum to Array dynamically in C#
usingSystem;
usingSystem.Collections.Generic ;
usingSystem.Linq;
usingSystem.Text;
namespaceProgramEmumtoArray
{
classProgramEmumtoArray
{
staticvoidMain(string[]args)
{
string[]people =Enum.GetNames(typeof(People));
foreach(var person inpeople)
{
Console.WriteLine(person);
}
Console.Read(); }
enumPeople
{
Gandhi, Anthony, Obama, Mani
}
}
}
Output:
Dynamic enumeration of Enum in C#
8/10/2019 C Sharp _ w3mentor - Part 3
8/10
usingSystem;
usingSystem.Collections.Generic ;
usingSystem.Linq;
usingSystem.Text;
namespacew3mentorConsoleApp
{
classProgram
{
staticvoidMain(string[]args)
{
foreach(var car inEnum.GetValues(typeof(Cars)))
{
Console.WriteLine(Enum.GetName(typeof(Cars), car));
}
Console.Read(); }
enumCars
{
Ferrari, Polo, GMC, FordExplorer
}
}
}
Output:
Sorting a hashtable in C#
Hashtable myHashTable =newHashtable();
myHashTable.Add("1", "dotnet");
myHashTable.Add("2", "tutorials");myHashTable.Add("3", "w3mentor");
ListmyList =newList();
foreach(var key inhash.Keys)
{
myList.Add(int.Parse(key.ToString()));
}
//sort the hashtable
myList.Sort();
foreach(var item inmyList)
{
Console.WriteLine(string.Format("{0},{1}", item, hash[item.ToString()]));
}
Console.Read();
Cloning C# objects using MemberwiseClone
publicCarClass GetCopy()
{
returnMemberwiseClone()asCarClass;
}
CarClass beta =newCarClass();
CarClass newcar =beta.GetCopy();
boolareCarsEqual =ReferenceEquals(beta, newcar);
Console.WriteLine("Are cars Equal?: {0}",areCarsEqual);
Example of stringbuilder append operation in C#
voiddemoAppendSB()
{
StringBuilder sb;sb =newStringBuilder("This is the existing text");
sb.Append("This will be appended");
Console.WriteLine("sb.Append(\"Appended\"): {0}",sb);
}
Delete newly created file from directory in C#
voiddeleteNewFile(stringdirPath)
{
DirectoryInfo directInfo =newDirectoryInfo(dirPath);//read directory to enumerate files
FileInfo[]filelist =directInfo.GetFiles();
var fileList =fromn infilelist selectnew{FileName =n.FullName, CreationDate =n.CreationTime.ToLongDateString()};//get list of
var latestFile =(fromm infileList orderby m.CreationDatedescending selectm.FileName).First();//get the first file from th
Console.WriteLine(latestFile);//display filename before deleting
8/10/2019 C Sharp _ w3mentor - Part 3
9/10
FileInfo file =newFileInfo(latestFile);
file.Delete();
Console.WriteLine(latestFile +" has been deleted");
Console.ReadKey();
}
Latest Tutorials & Code Snippets
Randomly select element from python list
Use append to merge two lists in python
Merge two lists in python
Display 5 posts in wordpress using wp_queryDisplay post title and content in wordpress theme
Common template tags in wordpress
Simple wordpress data loop
connect asynchronously to sql server
Test for websockets support in browser
websockets bufferedAmount example
Test if two matrices are equal in C#
Create identity matrix in C#
Parallel matrix multiplication in C# using task parallel library
Matrix multiplication in C#
Create matrix in C#
TreeMap in Java
HashMap in Java
Use TreeSet to parse sentences for word count in Java
HashSet in Java
PriorityQueue in Java
Reference Guides
C Library Functions
C# simple data types reference
Correlation between the UTF-8, UTF-16 and UTF-32
CSS 2 Reference Guide
Decimal, binary, octal and hexadecimal equivalents
HTML 5 Deprecated Attributes
HTML 5 Deprecated Tags
HTML 5 Tags Reference
HTML Character Encoding
HTML Deprecated Tags
HTML Entities
HTML Fonts Reference
HTML Quick Reference
HTML URL Encoding
HTML/XHTML Tags Reference
Javascript Events Reference
Javascript Functions Guide
jQuery Quick Reference
Media Kit
New types for input tag in HTML 5
PERL Functions Reference
Standard C string library functions
Tags introduced in HTML 5
Unicode Character Ranges Reference
Unix commands guide
Previous PageNext Page
8/10/2019 C Sharp _ w3mentor - Part 3
10/10
Popular Tags
arraysassemblyclasscommand linecomputation contractdatabasedata typesdirectoryemailerroreventsexamplefilefile handlingfilestreamform postform processingfunctionsGlobalsinterview questionslogisticsloopingmailMVCnumericalobjectobject orientedqualityreadreferenceregexriskrpcserializationsessionssocialsocketsquery stringtimevariables viewsxmlxml parsing
Home | Site Map | About W3mentor| Contact Us | FAQ | Link to W3mentor
Copyright 2012 Dotfluent Network.