void

Sending items in a LINQ sequence to a method that returns void

▼魔方 西西 提交于 2019-12-04 23:47:53
Often while I'm dealing with LINQ sequences, I want to send each item to a method returning void, avoiding a foreach loop. However, I haven't found an elegant way to do this. Today, I wrote the following code: private StreamWriter _sw; private void streamToFile(List<ErrorEntry> errors) { if (_sw == null) { _sw = new StreamWriter(Path.Combine (Path.GetDirectoryName(_targetDatabasePath), "errors.txt")); } Func<ErrorEntry, bool> writeSelector = (e) => { _sw.WriteLine(getTabDelimititedLine(e)); return true; }; errors.Select(writeSelector); _sw.Flush(); } As you can see, I write a lambda function

When can “void()” be used and what are the advantages of doing so

為{幸葍}努か 提交于 2019-12-04 21:05:59
I started learning the C language recently, and have noted the function "void()", however, I would like to know what it does and it's best points of application, also perhaps an alternative to void that is potentially more productive. Thank you. There is no function called void , but a function can be declared with a return type of void . This means that the function doesn't return a value. void DoSomething(...) { .... } Update void can also be used to indicate to the compiler that the function does not take any arguments. For example, float CalculatePi(void) { .... } John R. Strohm void in C

What does—or did—“volatile void function( … )” do?

我只是一个虾纸丫 提交于 2019-12-04 16:41:20
问题 I've seen How many usage does "volatile" keyword have in C++ function, from grammar perspective? about use of the volatile keyword on functions, but there was no clear explanation of what Case 1 from that question did. Only a statement by one of the respondents that it seemed pointless/useless. Yet I cannot quite accept that statement, since the AES software implementations for GNUC have been used for literally years, and they have a number of functions like this: INLINE volatile void

Are class constructors void by default?

怎甘沉沦 提交于 2019-12-04 16:23:52
I have been reading on class constructors in C#. Examples are showing overloaded class contructors. And all of them do not have a void keyword and neither they have a return value.. e.g. public Class myClass { public myClass() { } public myClass(int id) { } //other class memeber go here... } 1) So is it correct to say C# constructors are void by default? 2) Does the same applies to Java as well? no, they are constructors, if anything, you can think of them as returning an object of the class they are from. But, they aren't normal method/functions No Constructors implicitly return class type

C# thread method return a value? [duplicate]

断了今生、忘了曾经 提交于 2019-12-04 07:59:07
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Access return value from Thread.Start()'s delegate function public string sayHello(string name) { return "Hello ,"+ name; } How can i use this method in Thread? That ThreadStart method just accept void methods. I'm waiting your helps. Thank you. 回答1: Not only does ThreadStart expect void methods, it also expect them not to take any arguments! You can wrap it in a lambda, an anonymous delegate, or a named static

Can't compile with void variable in C

蓝咒 提交于 2019-12-04 07:54:00
test.c int main () { void a; return 0; } I use gcc to compile but it gives me an error: error: variable or field 'a' declared void From what I read here , I thought I can declare void variable without problem. As your link states: A variable that is itself declared void (such as my_variable above) is useless; it cannot be assigned a value, cannot be cast to another type, in fact, cannot be used in any way. This means that although syntactically correct, a void declaration is not useful to anything, this is why GCC could consider it an error. Even if it would compile, you won't be able to do

void及void指针深层次探索

不问归期 提交于 2019-12-04 07:10:44
1.概述   许多初学者对C/C++语言中的void及void指针类型不甚理解,因此在使用上出现了一些错误。本文将对void关键字的深刻含义进行解说,并详述void及void指针类型的使用方法与技巧。    2.void的含义   void的字面意思是“无类型”,void *则为“无类型指针”,void *可以指向任何类型的数据。   void几乎只有“注释”和限制程序的作用,因为从来没有人会定义一个void变量,让我们试着来定义: void a;   这行语句编译时会出错,提示“illegal use of type 'void'”。不过,即使void a的编译不会出错,它也没有任何实际意义。   void真正发挥的作用在于:   (1)对函数返回的限定;   (2)对函数参数的限定。   我们将在第三节对以上二点进行具体说明。   众所周知,如果指针p1和p2的类型相同,那么我们可以直接在p1和p2间互相赋值;如果p1和p2指向不同的数据类型,则必须使用强制类型转换运算符把赋值运算符右边的指针类型转换为左边指针的类型。   例如: float *p1; int *p2; p1 = p2;   其中p1 = p2语句会编译出错,提示“'=' : cannot convert from 'int *' to 'float *'”,必须改为: p1 = (float *)p2;  

Why the out put of below code is Thread[main,5,main]

冷暖自知 提交于 2019-12-04 07:01:03
问题 public class test1 { public static void main(String[] args) { // TODO Auto-generated method stub Thread t = Thread.currentThread(); System.out.println(t); } } Why the output of above code is - Thread[main,5,main] ? Please Explain 回答1: Because thread.toString() returns a string representation of this thread, including the thread's name, priority, and thread group. 回答2: Returns a string representation of this thread, including the thread's name, priority, and thread group. Source: https://docs

accessing struct: derefrencing pointer to incomplete type

不打扰是莪最后的温柔 提交于 2019-12-04 06:23:49
问题 When I'm trying to use and access the pointers to my structs i keep getting the annoying message of "dereferencing pointer to incomplete type" .... For example in my user.h file I have this typedef : typedef struct FacebookUser_t* User; and in my user.c file which includes user.h I have this struct: struct FacebookUser_t {...}; So when I need a pointer to that struct I only use User blabla; it seems to work, and I add it to generic list as Element which is void* and that's the typedef for it

Is 'void' a valid return value for a function?

与世无争的帅哥 提交于 2019-12-04 05:27:15
private void SaveMoney(string id...) { ... } public void DoSthWithMoney(string action,string id...) { if(action=="save") return SaveMoney(string id); ... } Why won't C# let me return the void of the private function back through the public function? It even is the same data type "void"... Or isn't void a data type? Is the following code really the shortest workaround? if(action=="save") { SaveMoney(string id); return; } void is not an actual return (data)type! void says there is no result. So you can not return a value in a method that's declared void even though the method you're calling is