New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of C#
C#
protected void Button2_Click(object sender, EventArgs e)
        {
            string uri = "http://quality.osm.no";
            Uri weburi = new Uri(uri, false);
            StringBuilder sbuild = new StringBuilder();
            string temp = "";
            try
            {
                HttpWebRequest webrequest = (HttpWebRequest) WebRequest.Create(weburi);
                CredentialCache myCache = new CredentialCache();
by nobodybutca   Tuesday @ 9:05pm
9 Views
no comments
 
C#
public class StoredProcedureGateway : IExternalSystemGateway {
  public object Call(string procedure, object[] params) {
    // call sproc
  }
}
 
public class SomeStoredProcedureParameters : IIssueExternalCalls {
  public string SomeString;
  public int SomeInt; 
  public object IssueWith(IExternalSystemGateway gateway) {
by togakangaroo   Monday @ 10:59am
13 Views
no comments
 
C#
[TestClass]
public class MyTests
{
    static System.Threading.ManualResetEvent m_Trigger
        = new System.Threading.ManualResetEvent(false);
 
    [TestMethod]
    private static void MyTest()
    {
        Exception ex = null;
by Jerry Nixon   August 21, 2010 @ 9:22pm
Tags: Unit Test, C#
16 Views
no comments
 
C#
 
class PrototypeTest
{
    static void Main()
    {
        dynamic pastry1 = new Prototype();
        pastry1.PastryType = "cake";
        pastry1.Cake = new Func<string>(() => "awesome");
 
        Console.WriteLine("Pastry 1's {0} is {1}.", pastry1.PastryType, pastry1.Cake());
by Andy Sherwood   August 17, 2010 @ 9:22am
41 Views
no comments
 
C#
using System;
using System.Runtime.InteropServices;
using System.Security;
 
public static class GuidUtil
{
   [SuppressUnmanagedCodeSecurity]
   [DllImport("rpcrt4.dll", SetLastError = true)]
   private static extern int UuidCreateSequential(out Guid value);
by kzu   August 01, 2010 @ 7:25pm
Tags: Guid, C#
124 Views
no comments
 
C#
public DateTime getIndianStandardTime()
{
 TimeZoneInfo IND_ZONE=TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
 return TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, IND_ZONE);
}
by pandiyachendur   July 16, 2010 @ 2:17am
27 Views
no comments
 
C#
// 3.5:
var radioGroups = this.Controls.OfType<RadioGroup>().ToList();
 
// old way using recursion:
var radioGroups = GetAllRadioGroups(this.Controls);
 
/// <summary>
/// Return a list of radiogroup controls within the current controls collection, recursively
/// </summary>
/// <param name="controls"></param>
by Cat   July 06, 2010 @ 4:33am
Tags: C#
23 Views
no comments
 
C#
public string GetMonthNumberFromAbbreviation(string mmm)
{
string[] monthAbbrev =
CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedMonthNames;
int index = Array.IndexOf(monthAbbrev, mmm) + 1;
return index.ToString("0#");
}
by pandiyachendur   June 30, 2010 @ 11:57pm
Tags: c#
43 Views
no comments
 
C#
public string GetRandomPasswordUsingGUID(int length)
{
string guidResult = System.Guid.NewGuid().ToString();
guidResult = guidResult.Replace("-", string.Empty);
if (length <= 0 || length > guidResult.Length)
throw new ArgumentException("Length must be between 1 and " + guidResult.Length);
return guidResult.Substring(0, length);
}
by pandiyachendur   June 30, 2010 @ 11:56pm
Tags: c#
29 Views
no comments
 
C#
 
 
public string GetJSONString(DataTable Dt)
{
string[] StrDc = new string[Dt.Columns.Count];
string HeadStr = string.Empty;
for (int i = 0; i <>
{
StrDc[i] = Dt.Columns[i].Caption;
HeadStr += "\"" + StrDc[i] + "\" : \"" + StrDc[i] + i.ToString() + "¾" + "\",";
by pandiyachendur   June 30, 2010 @ 11:55pm
Tags: c#
60 Views
no comments
 
C#
/************************************************************/
/* Set expectations for a method to be called only once     */
/************************************************************/
// NMock:
Expect.Once.On(mockLookupList).Method("Clear");
 
// Rhino Mocks
mockLookupList.Expect(x => x.Clear()).Repeat.Once();
 
/************************************************************/
by Cat   June 22, 2010 @ 12:53pm
31 Views
no comments
 
C#
var results = 
    from e in exposureGrouping
    group e by new { e.Category, e.Area } into g
    orderby g.Key.Category, g.Key.Area
    select new WorldwideExposure
    {
        Category = g.Key.Category,
        Area = g.Key.Area,
        Open_Market = g.Where(x => x.ClassCode == "OM").Sum(x => x.Usd_Gross_Exposure),
        North_American_Binders = g.Where(x => x.ClassCode == "NA").Sum(x => x.Usd_Gross_Exposure),
by Cat   June 16, 2010 @ 1:47am
Tags: C#, LINQ
74 Views
no comments
 
C#
var groupedResults =
    from r in results
    group r by r.Category into g
    select new
    {
        Category = g.Key,
        Results = g
    };
 
by Cat   June 16, 2010 @ 1:42am
Tags: C#, LINQ
34 Views
no comments
 
C#
using System;
using System.Runtime.InteropServices;
 
namespace ShivaVG
{
    public enum VGboolean {
                VG_FALSE = 0,
                VG_TRUE  = 1 };
 
    public enum VGUArcType {
by Ross   June 07, 2010 @ 9:25am
59 Views
no comments
 
C#
var reportTypes = new Dictionary<int, string> () 
    { 
        {(int)ReportType.Country, "By Country"},
        {(int)ReportType.CountryState, "By Country, State"},
        {(int)ReportType.CountryStateZone, "By Country, State, Zone"},
        {(int)ReportType.CountryStatePostCode, "By Country, State, Postal code"},
        {(int)ReportType.CountryZone, "By Country, Zone"},
        {(int)ReportType.CountryStateCounty, "By Country, State, County"},
    };
by Cat   June 01, 2010 @ 4:55am
64 Views
no comments
 
C#
private static bool AttemptInsertUniqueItem<T>(T item, Action<T> insert)
{
    bool success = false;
 
    try
    {
        insert(item);
        success = true;
    }
    catch (SqlException sqlEx)
by Jon Sagara   May 26, 2010 @ 11:20pm
59 Views
no comments
 
C#
public class ConsoleSpinner
{
    const int MaxSegmentIndex = 3;
 
    readonly char[] _segments = new [] {  '\\', '|', '/', '-'};
    readonly int _left;
    readonly int _top;
 
    int _curIndex;
by Al Gonzalez   May 18, 2010 @ 6:43am
141 Views
no comments
 
C#
public interface ICriteriaQuery<TEntity>
{
    DetachedCriteria Criteria { get; }
}
 
public interface ILinqQuery<TEntity>
{
    Expression<Func<TEntity, bool>> Expression { get; }
}
by Liam   May 13, 2010 @ 10:40pm
76 Views
no comments
 
C#
        [Test]
        public void CompileStringReversal()
        {
            var coffee_script =
@"reverse: (string) ->
   string.split('').reverse().join ''
 
   alert reverse '.eeffoC yrT'";
            var expected = 
@"var reverse;
by Liam   May 08, 2010 @ 10:28pm
76 Views
no comments
 
C#
public static class TinyUrl
    {
        private static readonly Random Random = new Random();
 
        public static string Get()
        {
            int random = Random.Next();
            return Base62ToString(uint.MaxValue);
        }
by Mikael Henriksson   April 30, 2010 @ 5:18am
Tags: TinyUrl, C#
57 Views
no comments
 
C#
public class GenericComparer<T> : IComparer<T>
{
    public List<Tuple<string, bool>> Comparisons { get; set; }
 
    public int Compare(T x, T y)
    {
        int returnValue = 0;
        IComparable xval;
        IComparable yval;
        
by JamesEggers   April 28, 2010 @ 8:30am
Tags: C#, Sorting
59 Views
no comments
 
C#
public class SqlAppender : AppenderSkeleton
{
    private static readonly string CommandText = "INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)";
 
    public string ConnectionString { get; set; }
 
    protected override void Append(LoggingEvent loggingEvent)
    {
        using (var conn = new SqlConnection(ConnectionString))
        using (var cmd = new SqlCommand(CommandText, conn))
by Jon Sagara   April 25, 2010 @ 1:14am
64 Views
no comments
 
C#
using System;
using System.Runtime.InteropServices;
using System.Threading;
using AcroPDFLib;
 
// Related to: http://stackoverflow.com/questions/2702164
namespace ComConsoleApplication
{
    [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000016-0000-0000-C000-000000000046")]
    public interface IMessageFilter
by knutkj   April 23, 2010 @ 3:40pm
80 Views
no comments
 
C#
slickGrid.AddColumn(
    Column.ForId("riga")
        .Named("Riga")
        .ForField("id")
        .WithEditorFunction("TextCellEditor")
        .WithSetValueHandler("updateItem")
        .WithBehavior(Column.Behavior.selectAndMove)
    ).AddColumn(
    Column.ForId("codice")
        .Named("Codice")
by Andrea Balducci   April 22, 2010 @ 1:50am
177 Views
no comments
 
C#
namespace Nowcom.Quicksilver
{
    using System.ComponentModel;
    using System.Linq.Expressions;
    using System;
 
    public abstract class PropertyChangedBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
by Robert Kozak   April 21, 2010 @ 3:52pm
110 Views
1 comments
 
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate