376 Posted Topics

Member Avatar for yayaza

Where is the user input? Why is factorial a string? Why are you assigning an integer to a string? That while statement won't compile. The factorial assigment statement is incorrect. The final statement will not compile.

Member Avatar for finito
0
116
Member Avatar for DaveTran

Your extension method is returning a new Vector2. So for your code to work, you would need to update the last part to this [CODE]vec = vec.SetLength(10);[/CODE] With that in mind, you may want to update the method name to something more descriptive of what is happening since you are …

Member Avatar for DaveTran
0
143
Member Avatar for sdhawan

Hashtable is from the pre-generic days and stores keys and values as objects rather than their native types. As a result, you need to unbox the objects when you wish to use them in the manner you are. [CODE] string def = (string)hash[elem.Word]; // should do the trick [/CODE] To …

Member Avatar for apegram
0
1K
Member Avatar for PierlucSS

Add and AddRange should not "yield return" anything. They should be methods of type "void" that simply add to your collection. I would change your class to something like this [CODE] public class HrefCollection : IEnumerable<Href> { private List<Href> _hrefs = new List<Href>(); public void Add(Href href) { _hrefs.Add(href); } …

Member Avatar for PierlucSS
1
239
Member Avatar for sdhawan

[B]A)[/B] Look into using parameterized queries. Example: [CODE] string sql = "Insert Into SomeTable (SomeField) Values (@someField)"; SqlParameter someField = new SqlParameter("@someField", "my value"); SqlCommand command = new SqlCommand(sql, connection); command.Parameters.Add(someField); [/CODE] B) [B]or[/B] perform some manipulation on the strings before you insert them into your SQL statements. Unescaped apostrophes …

Member Avatar for kvprajapati
-1
727
Member Avatar for Isaaac

[QUOTE=Isaaac;1225015]Try this: File.WriteAllLines("data.log", richTextBox1.Lines); Works perfectly! But how do i append that text? i don't want to delete previous log..[/QUOTE] Use the File.AppendAllLines method.

Member Avatar for Isaaac
0
828
Member Avatar for steveh44

Overall, there will be little difference. When you use the Load overload that accepts a string path for the file, it is going to create a reader from that file and then use it to load the XmlDocument. When you pass in the reader, you've obviously taken care of that …

Member Avatar for apegram
0
140
Member Avatar for zizi

Each of those methods is going to return a boolean if the value is contained within the dictionary. You appear to be using a string variable to as the test, so it assumes the TValue type of the dictionary is a string. You would be using the methods in the …

Member Avatar for apegram
0
99
Member Avatar for gloris

A few things. 1) Look at the compilation errors given to you. You should have several messages telling you that "id", "name", and "time" are not properties of the XmlTextReader class. Work to try to fix your mistakes. 2) Since .NET 2.0, explicit usage of the XmlTextReader class has been …

Member Avatar for apegram
0
96
Member Avatar for andy_1234

Looks like homework. What have you tried? Show some code and maybe you'll get some help. As a start, I suggest looking at the System.Xml.Linq namespace. That will at least get you started on reading the XML into a usable collection. You're probably going to need do some sort of …

Member Avatar for andy_1234
0
373
Member Avatar for PEFCa

[CODE] For Each tb As TextBox In Me.Controls.OfType(Of TextBox)() ' do something with tb Next [/CODE]

Member Avatar for kvprajapati
0
154
Member Avatar for romanoff

Could you perhaps be more specific. What are you trying to accomplish?

Member Avatar for nick.crane
0
75
Member Avatar for DaveTran

[QUOTE=DaveTran;1215475] When adding parameters to the dictionary they don't update when the original parameter updates. For example [CODE] Foo foo = new Foo(); debug_Tools.AddParameter("Foo is feeling good?", foo.isSexy); foo.isSexy = true; [/CODE] will display false, even though the parameter has been changed to true. How can I fix this?[/QUOTE] You're …

Member Avatar for apegram
0
167
Member Avatar for zizi

Eric Lippert of the C# compiler team is the midst of writing a series on binary trees, arbitrary trees, and "every program there is" along these very same lines. [url]http://blogs.msdn.com/ericlippert/archive/2010/04/19/every-binary-tree-there-is.aspx[/url] [url]http://blogs.msdn.com/ericlippert/archive/2010/04/22/every-tree-there-is.aspx[/url] [url]http://blogs.msdn.com/ericlippert/archive/2010/04/26/every-program-there-is-part-one.aspx[/url] [url]http://blogs.msdn.com/ericlippert/archive/2010/04/29/every-program-there-is-part-two.aspx[/url] [url]http://blogs.msdn.com/ericlippert/archive/2010/05/03/every-program-there-is-part-three.aspx[/url] [url]http://blogs.msdn.com/ericlippert/archive/2010/05/06/every-program-there-is-part-four.aspx[/url] [url]http://blogs.msdn.com/ericlippert/archive/2010/05/10/every-program-there-is-part-five.aspx[/url] Part 6 will probably be up Thursday.

Member Avatar for zizi
0
314
Member Avatar for steveh44

Here's a recursive function I recently wrote to go through a set of folders and subfolders to rename images (they had a .jpeg extension, needed to just be .jpg). [CODE] string path = @"Q:\some_company\some_path\"; Action<string> fileRenamer = null; fileRenamer = directoryPath => { string[] files = Directory.GetFiles(directoryPath, "*.jpeg"); foreach (string …

Member Avatar for Sodabread
0
578
Member Avatar for vispyr

Have the method accept a parameter of type Pet rather than of type Dog or Cat. With Name and Age being properties of the base class rather than the derived types, you will be able to access them just fine within the method.

Member Avatar for apegram
0
62
Member Avatar for DaveTran

Are you unable or just unwilling to use the generic interface IComparer<T>? With the generic interface implementation, the method natively accepts Foo arguments. However, with the plain interface, you are left with objects and you will simply have to cast. [CODE] class FooComparer : IComparer<Foo> { public int Compare(Foo x, …

Member Avatar for apegram
0
984
Member Avatar for chandruswami

Consider this method: [CODE] string[] excludedValues = { string.Empty, "-", " " }; string value = "a, ,b,-,c,d, ,"; string[] values = value.Split(',').Except(excludedValues).ToArray(); [/CODE]

Member Avatar for thines01
0
185
Member Avatar for Lolalola

A time in the format hh:mm:ss will parse into a date as today's date plus the parsed time. So 17:10:03 would parse as April 27, 2010 5:10:03 PM. With that in mind, you would be able to simply do a straight comparison of your parsed time value and the currrent …

Member Avatar for apegram
0
97
Member Avatar for digozz
Member Avatar for customtshirts
Member Avatar for krishnisilva
Member Avatar for sweetypie123

Replace * with % Also, if you want something that starts with S, do not put a wildcard before it. That will match Sam, aSm, amS, etc.

Member Avatar for sweetypie123
0
136
Member Avatar for lllllIllIlllI

[QUOTE=Narue;1147668][B]>Nobody twisting your arm to click on the thread, is there?[/B] In theory, excessive posts could fill up the database and slow the site down enough to cost Dani more money in maintaining the status quo, and in turn she could start charging subscriptions. Every "I HAZ XXX POSTS D00D!!11" …

Member Avatar for bumsfeld
10
248
Member Avatar for brettbed

You can also drop the explicit coding of the loop in favor of using the Any extension method. Sample: [CODE] int[] array = { 1, 2, 3, 4, 5 }; bool hasEvenElement = array.Any(item => item % 2 == 0); [/CODE] In this example, all it is doing is checking …

Member Avatar for brettbed
0
581
Member Avatar for bill_kearns

Some realms of the internet would recommend using the HTML Agility Pack, which is a open source library that parses HTML files. I've never used it, so I can't give you any pointers. [url]http://htmlagilitypack.codeplex.com/[/url]

Member Avatar for apegram
0
129
Member Avatar for complete

You could declare an array of LinkedList objects like this [CODE] LinkedList<int>[] array = new LinkedList<int>[5]; [/CODE] Next question: [i]Then how would you pass the filename to r[0] and r[1] which would normally be passed in the constructor?[/i] These statements here [CODE] XmlTextReader[] r; r = new XmlTextReader [2]; [/CODE] …

Member Avatar for RicardoE
0
682
Member Avatar for Omar123

List<string> as implemented is a .NET 2.0+ construct, and your web service could potentially be consumed by any number of clients. Being that the generic list is a wrapper around a backing array, the service will expose the method or property as returning an array of strings (string[]) rather than …

Member Avatar for Omar123
0
1K
Member Avatar for ana12

An apple a day keeps the doctor away. Am I right or am I right. Or am I right.

Member Avatar for Lardmeister
-5
256
Member Avatar for bunnyboy

When you're calling your extension method, you would call it in such a manner as [CODE]string newString = someString.Remove(a, b); // where a and b are characters[/CODE] A couple of points to consider: 1) System.String already has a Remove method that accepts two parameters of type int. 2) char values …

Member Avatar for apegram
0
357
Member Avatar for rcsamich81

Here's an example of creating a list of visible buttons on a form and hiding them for one second and them making them visible again. [CODE] Dim buttons = (From btn As Button In Me.Controls.OfType(Of Button)() _ Where btn.Visible = True _ Select btn).ToList() Dim button As Button For Each …

Member Avatar for rcsamich81
0
3K
Member Avatar for yookify
Re: Hai

[CODE]If (textBox1.Text.Equals(textBox2.Text)) Then ' your text is equal Else ' your text is not equal End If[/CODE]

Member Avatar for yookify
0
97
Member Avatar for DaveTran

That is subjective. In a business application, that would have to determined as part of the requirements. First, you would want to determine if two (or more) elements having the same value is acceptable or an error condition. If it is permissible, then you or the customer must determine which …

Member Avatar for apegram
0
129
Member Avatar for farsen

If you want to be able to access those labels after your loop, you can (a) store them in an array (b) store them in a List<Label> (c) store them paired up with their corresponding Item objects in a Dictionary<Item, Label> (d) access them via the form's Control collection (assuming …

Member Avatar for Venjense
0
197
Member Avatar for SubatomicRhythm

[CODE]Dim input As String = "this is a sentence" Dim words() As String = input.Split(" "c) For Each word As String In words ' do something here Next[/CODE]

Member Avatar for apegram
0
173
Member Avatar for buzzykerbox

You can certainly implement a counting mechanism and try to obtain values and re-obtain a new value if your counter at a given position has already met the limit. Towards the end of the process, you would be need to perform more and more checks because your odds of getting …

Member Avatar for buzzykerbox
0
117
Member Avatar for chandruswami

It's fairly trivial to move an element using Linq to XML (System.Xml.Linq namespace). Here's one such method. [CODE] XDocument document = XDocument.Load(xmlFile); XElement element = document.Root.Element("Connection"); // gets first Connection element element.Remove(); document.Root.Add(element); // adds after other elements document.Save(newFile); [/CODE]

Member Avatar for chandruswami
-1
123
Member Avatar for Acadian

I haven't tested the code (beyond this) or looked for other issues, but the array initializations are off. The first set of strings includes 196 elements, but the second is only 191. A 2D array needs to be uniform.

Member Avatar for apegram
1
167
Member Avatar for praveen_dusari

adatapost posted a good article if you want to do some cool things to the image as you're creating a thumbnail. If all you want to do is resize an image, the code is fairly simple. Here is a class I use whenever I need to do some resizing. It …

Member Avatar for carrzkiss
0
423
Member Avatar for hkBattousai

The property "Name" is the syntactic sugar that allows you to fluently set or obtain the value of the backing field, "name." In other languages, you would not typically have such a property, you would have distinct getter and setter methods for working with the value. [CODE] private string name; …

Member Avatar for hkBattousai
0
426
Member Avatar for nirveshverma

After you get a good distance off the ground (meaning: don't let this be your first book), go with [B]C# In Depth[/B] by Jon Skeet. Excellent book. Before that, you may want to try [B]Essential C#[/B] by Mark Michaelis.

Member Avatar for apegram
1
135
Member Avatar for tjfitz68

Look at the following Math class functions. Math.Ceiling Math.Round (specifically, the overload using the MidpointRounding enum) Math.Floor

Member Avatar for tjfitz68
0
83
Member Avatar for plowguy

The DateTime struct has .Add___ methods that allow you to add values to a datetime and retrieve a new date. For getting a date in the past, you simply have to make the parameter negative. Something like [CODE] DateTime today = DateTime.Now.Date; DateTime twoWeeksAgo = today.AddDays(-14); [/CODE]

Member Avatar for plowguy
0
77
Member Avatar for vodkasoda
Member Avatar for lewashby

List<T> is a strongly-typed collection of objects of type T. In your example, you have a collection of Surface objects. [CODE] List<int> ints; List<string> strings; List<double> doubles; List<Foo> foos; [/CODE] It is a "generic" collection. Generics were introduced to C# and .NET in the 2.0 release. Prior to that, you …

Member Avatar for apegram
0
122
Member Avatar for bunnyboy

You can solve it by creating a concrete type. Here's one such type, simply named LetterHolder. [CODE] class LetterHolder { public char Letter { get; set; } public int Index { get; set; } } [/CODE] And then getting a dictionary. [CODE] char[] Pattern = "GCAGAGAG".ToCharArray(); Dictionary<char,int> dictionary = Pattern …

Member Avatar for bunnyboy
0
102
Member Avatar for stryker4526

I don't work with recursion much, if ever, so I don't have any idea whether my quick idea is recursive enough or if it matters. [CODE] static void Main(string[] args) { int[,] matrix = new int[3, 5] { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, …

Member Avatar for Wizardsr66
0
4K
Member Avatar for lewashby

Think of it as the first line creating a reference to a logical grouping of common elements. The subsequent lines are actually creating instances of the type of the element. The reason arrays are beneficial goes back to the first statement, the common elements are grouped together, which allows you …

Member Avatar for apegram
0
141
Member Avatar for wyett

Rethink the problem. At least the "odd" part. Instead of generating a number from 1 to 8 and then checking if it's odd, instead consider generating a number from 0 to 3. Multiply that number by 2 and add 1. It will always be odd. 0 -> 1 1 -> …

Member Avatar for wyett
0
126
Member Avatar for lewashby

[CODE] MenuMaker menu = new MenuMaker() { Randomizer = new Random() }; [/CODE] That's C# 3.0's object initializer feature. New in 3.0, you are able to set public properties at class instantiation time. It would be the same as writing this: [CODE] MenuMaker menu = new MenuMaker(); menu.Randomizer = new …

Member Avatar for apegram
0
185

The End.